commit 8bfb4afac7c2127ecc82ae6b39b97bada8b158c1 Author: 202510715092 REZA BUDI SAPUTRA <202510715092@mhs.ubharajaya.ac.id> Date: Sat Apr 25 21:18:21 2026 +0700 Upload files to "/" diff --git a/4.50.PY b/4.50.PY new file mode 100644 index 0000000..61607ff --- /dev/null +++ b/4.50.PY @@ -0,0 +1,31 @@ +def bisa_bayar(harga, pecahan): + # Menggunakan DP (subset sum) + dp = set() + dp.add(0) + + for uang in pecahan: + baru = set(dp) + for nilai in dp: + total = nilai + uang + if total == harga: + return "YA" + if total < harga: + baru.add(total) + dp = baru + + return "YA" if harga in dp else "TIDAK" + + +# Input beberapa baris (contoh seperti soal) +data = [ + [4000, 200, 50, 25], + [2200, 1000], + [5500, 2000, 200, 100] +] + +# Proses dan output +for i, baris in enumerate(data, start=1): + harga = baris[0] + pecahan = baris[1:] + hasil = bisa_bayar(harga, pecahan) + print(f"#{i}: {hasil}") \ No newline at end of file