解题思路:
注意事项:
参考代码:
n,w=map(int,input().split()) vb=[0] wb=[0] for i in range(n): wet,val=map(int,input().split()) wb.append(wet) vb.append(val) dp=[[0 for i in range(w + 1)] for j in range(n + 1)] for i in range(1,n+1): for j in range(1,w+1): if (j>=wb[i]): dp[i][j]=max(dp[i-1][j],dp[i-1][j-wb[i]]+vb[i]) else: dp[i][j] = dp[i-1][j] print(dp[-1][-1])
0.0分
0 人评分