From 8bfb4afac7c2127ecc82ae6b39b97bada8b158c1 Mon Sep 17 00:00:00 2001 From: 202510715092 REZA BUDI SAPUTRA <202510715092@mhs.ubharajaya.ac.id> Date: Sat, 25 Apr 2026 21:18:21 +0700 Subject: [PATCH] Upload files to "/" --- 4.50.PY | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 4.50.PY 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