题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6772
博客园食用:https://www.cnblogs.com/lonely-wind-/p/13374448.html
CSDN食用:https://blog.csdn.net/qq_43906000/article/details/107569361
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:
D M G = ( 100 + ∑ i ∈ S a i ) ( 100 + ∑ i ∈ S b i ) ( 100 + ∑ i ∈ S c i ) ( 100 + ∑ i ∈ S d i ) DMG=(100+∑_{i∈S}a_i)(100+∑_{i∈S}b_i)(100+∑_{i∈S}c_i)(100+∑_{i∈S}d_i) 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
emmm,看题目。。。似乎可以爆搜诶,试了一发DFS。。。一发A了emmm,那就似乎没什么好说的了,不过我听说随机数也能过,榜上0ms估计都是随机数刚过去的吧QAQ,我也写了波随机数。。。一言难尽可能是我姿势不对吧。
以下是AC的DFS代码:
#include
using namespace std;
typedef long long ll;
const int mac=100;
int tp[mac];
struct node
{
int a,b,c,d;
};
vector<node>equip[mac];
ll ans=0;
void dfs(int a,int b,int c,int d,int num)
{
if (num==0){
ll sum=(100LL+a)*(100LL+b)*(100LL+c)*(100LL+d);
ans=max(ans,sum);
return;
}
int sz=equip[num].size();
for (int i=0; i<sz; i++){
a+=equip[num][i].a; b+=equip[num][i].b;
c+=equip[num][i].c; d+=equip[num][i].d;
dfs(a,b,c,d,num-1);
a-=equip[num][i].a; b-=equip[num][i].b;
c-=equip[num][i].c; d-=equip[num][i].d;
}
}
int main(int argc, char const *argv[])
{
int t;
scanf ("%d",&t);
while (t--){
int n,k;
scanf ("%d%d",&n,&k);
int cnt=0;
ans=0;
for (int i=1; i<=k; i++) equip[i].clear();
memset(tp,0,sizeof tp);
for (int i=1; i<=n; i++){
int type,a,b,c,d;
scanf ("%d%d%d%d%d",&type,&a,&b,&c,&d);
if (!tp[type]) equip[++cnt].push_back(node{a,b,c,d}),tp[type]=cnt;
else equip[tp[type]].push_back(node{a,b,c,d});
}
dfs(0,0,0,0,cnt);
printf("%lld\n",ans);
}
return 0;
}