2020 Multi-University Training Contest 2 Lead of Wisdom (爆搜,dfs)
题面
Problem Description
In an online game, "Lead of Wisdom" is a place where the lucky player can randomly get powerful items.
There are k types of items, a player can wear at most one item for each type. For the i-th item, it has four attributes ai,bi,ci and di. Assume the set of items that the player wearing is S, the damage rate of the player DMG can be calculated by the formula:
DMG=(100+∑i∈Sai)(100+∑i∈Sbi)(100+∑i∈Sci)(100+∑i∈Sdi)
Little Q has got n items from "Lead of Wisdom", please write a program to help him select which items to wear such that the value of DMG is maximized.
Input
The first line of the input contains a single integer T (1≤T≤10), the number of test cases.
For each case, the first line of the input contains two integers n and k (1≤n,k≤50), denoting the number of items and the number of item types.
Each of the following n lines contains five integers ti,ai,bi,ci and di (1≤ti≤k, 0≤ai,bi,ci,di≤100), denoting an item of type ti whose attributes are ai,bi,ci and di.
Output
For each test case, output a single line containing an integer, the maximum value of DMG.
Sample Input
1
6 4
1 17 25 10 0
2 0 0 25 14
4 17 0 21 0
1 5 22 0 10
2 0 16 20 0
4 37 0 0 0
Sample Output
297882000
思路
爆搜题,直接dfs就好了。stl还是好用,哎,以后要学着多用stl,另外在比赛的时候要敢于去写代码,多找找感觉,会好的。
代码实现
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
struct node {
int a,b,c,d;
};
long long ans;
int n,m;
vector <node > va[55];
void dfs (int num,int a,int b,int c,int d) {
if (!num) {
ans=max (ans,1ll*a*b*c*d);
return;
}
int k=va[num].size ();
if (!k) return dfs (num-1,a,b,c,d);
for (int i=0;i<k;i++) dfs (num-1,a+va[num][i].a,b+va[num][i].b,c+va[num][i].c,d+va[num][i].d);
}
int main () {
int t;
cin>>t;
while (t--) {
cin>>n>>m;
ans=0;
for (int i=0;i<=m;i++) va[i].clear ();
for (int i=1,ty,y,z,x,e;i<=n;i++) {
cin>>ty>>x>>y>>z>>e;
node t={x,y,z,e};
va[ty].push_back (t);
}
dfs (m,100,100,100,100);
printf ("%lld",ans);
}
return 0;
}