HDUOJ 6772 Lead of Wisdom

HDUOJ 6772 Lead of Wisdom

题目链接

Problem Description

In an online game, “Lead of Wisdom” is a place where the lucky player can randomly get powerful items.

HDUOJ 6772 Lead of Wisdom_第1张图片

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,最复杂的情况就是 2 15 2^{15} 215 次,最多也就千万级,AC代码如下:

#include
using namespace std;
typedef long long ll;
struct node{
    ll a,b,c,d;
};
vector<node>v[55];
map<int,int>m;
int n,k,t,id,T;
ll ans;
void dfs(int u,int num,ll a,ll b,ll c,ll d){
    if(num==id){
        ans=max(ans,(100LL+a)*(100LL+b)*(100LL+c)*(100LL+d));
        return;
    }
    for(auto i:v[u]){
        dfs(u+1,num+1,a+i.a,b+i.b,c+i.c,d+i.d);
    }
}
int main()
{
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&k);
        for(int i=0;i<=n;i++) v[i].clear();
        m.clear();
        id=1;
        ans=0;
        while(n--){
            ll a,b,c,d;
            scanf("%d%lld%lld%lld%lld",&t,&a,&b,&c,&d);
            if(m[t]==0) m[t]=id++;
            v[m[t]].push_back({a,b,c,d});
        }
        dfs(1,1,0,0,0,0);
        printf("%lld\n",ans);
    }
}

你可能感兴趣的:(DFS,HDUOJ)