Advertisement
nq1s788

26 первая часть дп (рюкзак)

Dec 18th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #https://inf-ege.sdamgia.ru/problem?id=27423
  2. data = open('26_demo.txt').readlines()
  3. s, n = map(int, data[0].split())
  4. a = list(map(int, data[1:]))
  5. dp = [0] * (s + 1)
  6. for e in a:
  7.     nw = dp.copy()
  8.     for i in range(s):
  9.         if dp[i] != 0 and i + e <= s:
  10.             nw[i + e] = max(nw[i + e], dp[i] + 1)
  11.     nw[e] = max(nw[e], 1)
  12.     dp = nw.copy()
  13. print(max(dp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement