题解 | #采药#
采药
https://www.nowcoder.com/practice/d7c03b114f0541dd8e32ce9987326c16
t, n = map(int, input().split(" "))#01背包 time = [0 for i in range(n)] v = [0 for i in range(n)] dp = [0 for i in range(t + 1)] for i in range(n): time[i], v[i] = map(int, input().split(" ")) for i in range(n): for j in range(t, time[i] - 1, -1): dp[j] = max(dp[j], dp[j - time[i]] + v[i]) print(dp.pop())