第一行输入三个整数
代表英雄数量、总cost限制、双生英雄的对儿数。
此后
行,第
行输入两个正整数
代表第
个英雄的 cost 和战斗力。
此后
行,第
行输入三个正整数
代表第
和第
个英雄是双生英雄,同时上阵可以额外增加
战斗力。
除此之外,保证每个英雄最多只存在一对双生英雄关系。对于
的用例,额外保证
。
输出一个整数,代表组队的最大战斗力。
4 10 1 3 9 4 10 6 15 8 20 1 2 15
34
在这个样例中,小红可以选择上阵第一、二个英雄,获得
的战斗力。我们可以证明,这是符合要求的最大战斗力。
4 1 1 3 9 4 10 6 15 8 20 1 2 15
0
n, C, m = list(map(int, input().split())) heromax = 4 baseinfo = [] for _ in range(n): baseinfo.append(list(map(int, input().split()))) pairsinfo = [] for _ in range(m): pairsinfo.append(list(map(int, input().split()))) pairsdict = dict() for i in range(m): if pairsinfo[i][0] > pairsinfo[i][1]: pairsinfo[i][0], pairsinfo[i][1] = pairsinfo[i][1], pairsinfo[i][0] pairsdict[pairsinfo[i][0] - 1] = [pairsinfo[i][1] - 1, pairsinfo[i][2]] def dpfind(info: list[list[int]]): dplist = [[0 for _ in range(C + 1)] for _ in range(heromax + 1)] for heroidx in range(n): for cmax in range(C, -1, -1): for heronum in range(heromax): herocost = info[heroidx][0] if herocost <= cmax: # 如果这个英雄cost够低 newPower = info[heroidx][1] + dplist[heronum][cmax - herocost] # print(dplist) dplist[heronum + 1][cmax] = max(dplist[heronum + 1][cmax], newPower) if heroidx in pairsdict.keys() and heronum < heromax - 1: pairidx = pairsdict[heroidx][0] paircost = info[pairidx][0] if paircost + herocost <= cmax: newPower = ( info[heroidx][1] + info[pairidx][1] + pairsdict[heroidx][1] + dplist[heronum][cmax - herocost - paircost] ) dplist[heronum + 2][cmax] = max( dplist[heronum + 1][cmax], newPower ) return dplist[-1][-1] print(dpfind(baseinfo))