远景,第二题,0-1背包
if __name__ == "__main__": d = [int(x) for x in input().strip().split(' ')] e = [int(x) for x in input().strip().split(' ')] limit = int(input()) dp = [[0 for _ in range(limit+1)] for _ in range(len(d))] for i in range(limit+1): if d[0] <= i: dp[0][i] = e[0] # else: # dp[0][i] = 0 for i in range(1, len(d)): for j in range(limit+1): dp[i][j] = dp[i-1][j] if d[i] <= j: dp[i][j] = max(dp[i][j], e[i] + dp[i-1][j-d[i]]) print(dp[len(d)-1][limit])
#笔试题目##远景能源有限公司#