HDU - 6772 J - Lead of Wisdom(三维数组dfs)

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


int vis[55];
ll ans=0;
int t;
int no[55][55][4];
int nex[55];


void sol(int pos,int sumA,int sumB,int sumC,int sumD) {
    if(pos==k+1) {
        ll sum=1ll*sumA*sumB*sumC*sumD;
        ans=max(ans,sum);
        return;
    }
    int num=vis[pos];
    if(!num) {
        sol(nex[pos],sumA,sumB,sumC,sumD);
        return ;
    }
    for(int i=1; i<=num; i++)
        sol(pos+1,no[pos][i][0]+sumA,no[pos][i][1]+sumB,no[pos][i][2]+sumC,no[pos][i][3]+sumD);

}

int main() {
    int T=read();
    while(T--) {
        ans=0;
        memset(vis,0,sizeof(vis));
        n=read();
        k=read();
        for(int i=1; i<=n; i++) {
            t=read();
            vis[t]++;
            no[t][vis[t]][0]=read();
            no[t][vis[t]][1]=read();
            no[t][vis[t]][2]=read();
            no[t][vis[t]][3]=read();
        }
        //sort(no+1,no+n+1,cmp);
        int x=k+1;
        for(int i=k; i>=1; i--) {
            nex[i]=x;
            if(vis[i]) {
                x=i;
            }
        }
        sol(1,100,100,100,100);
        printf("%lld\n",ans);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值