来个 Python AC的 coding=utf-8 def bag(n, c, w, v): res = [[-1 for j in range(c + 1)] for i in range(n + 1)] for j in range(c + 1): res[0][j] = 0 for i in range(1, n + 1): for j in range(1, c + 1): res[i][j] = res[i - 1][j] if j >= w[i - 1] and res[i][j] < res[i - 1][j - w[i - 1]] + v[i - 1]: res[i][j] = res[i - 1][j - w[i - 1]] + v[i - 1] return res def show(n, c, w, res): x = [0 for i in range(n)] j = c for i in range(n,0,-1): if res[i][j] > res[i - 1][j]: x[i - 1] = 1 j -= w[i - 1] for i in range(n): if x[i]==1: print(i+1), if name == 'main': c = int(raw_input()) w = raw_input() w = w.split() for i in range(len(w)): w[i] = int(w[i]) v = raw_input() v = v.split() for i in range(len(v)): v[i] = int(v[i]) n = len(v) res = bag(n, c, w, v) show(n, c, w, res)
Yushuu:你的确很厉害,但是有一个小问题:谁问你了?我的意思是,谁在意?我告诉你,根本没人问你,在我们之中0人问了你,我把所有问你的人都请来 party 了,到场人数是0个人,誰问你了?WHO ASKED?谁问汝矣?誰があなたに聞きましたか?누가 물어봤어?我爬上了珠穆朗玛峰也没找到谁问你了,我刚刚潜入了世界上最大的射电望远镜也没开到那个问你的人的盒,在找到谁问你之前我连癌症的解药都发明了出来,我开了最大距离渲染也没找到谁问你了我活在这个被辐射蹂躏了多年的破碎世界的坟墓里目睹全球核战争把人类文明毁灭也没见到谁问你了😆