Problem J. CSGOTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 228 Accepted Submission(s): 109 Problem Description You are playing CSGO.There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose one Main Weapon and one Secondary Weapon. For each weapon, it has a composite score S. The higher the composite score of the weapon is, the better for you. Also each weapon has K performance evaluations x[1], x[2], …, x[K].(range, firing rate, recoil, weight…) So you shold consider the cooperation of your weapons, you want two weapons that have big difference in each performance, for example, AWP + CZ75 is a good choose, and so do AK47 + Desert Eagle. All in all, you will evaluate your weapons by this formula.(MW for Main Weapon and SW for Secondary Weapon) Now you have to choose your best Main Weapon & Secondary Weapon and output the maximum evaluation.
Input Multiple query.
Output Your output should include T lines, for each line, output the maximum evaluation for the corresponding datum.
Sample Input 2 2 2 1 0 233 0 666 0 123 0 456
2 2 1 100 0 1000 100 1000 100 100 0
Sample Output 543 2000 |
题意:
有n件主武器和m件副武器,所有武器都会有一个价值S和K种属性,当你选择一件主武器i和一件副武器j,得到的价值为,也就是两个武器的S要大,两件武器属性差要大。
做法:
最远n维曼哈顿距离。
用tmp[x]表示所有主武器的K种属性在状态为x(转为二进制)时的最大贡献。
比如数2 3 4 在状态001下就是(-2-3+4),0表示减,1表示加。
在得到(1<<k)个tmp后,对于副武器中的一个i的K种属性,也枚举个状态,然后和之前主武器中的相反状态相加,与之前的状态取一个异或值,维护答案取一个最大值即可。
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,save[35],tmp[10],ans;
int main(){
int t;
cin>>t;
while(t--){
scanf("%lld%lld%lld",&n,&m,&k);
memset(save,-125,sizeof(save));
for(int j=1;j<=n;j++){
scanf("%lld",&ans);
for(int i=1;i<=k;i++)
scanf("%lld",&tmp[i]);
for(int i=0;i<(1<<k);i++){
ll tmpans=ans;
for(int z=1;z<=k;z++){
if(i&(1<<(z-1))) tmpans+=tmp[z];
else tmpans-=tmp[z];
}
save[i]=max(save[i],tmpans);
}
}
ll aans=0;
for(int j=1;j<=m;j++){
scanf("%lld",&ans);
for(int i=1;i<=k;i++)
scanf("%lld",&tmp[i]);
for(int i=0;i<(1<<k);i++){
ll tmpans=ans;
for(int z=1;z<=k;z++){
if(i&(1<<(z-1))) tmpans-=tmp[z];
else tmpans+=tmp[z];
}
aans=max(aans,save[i]+tmpans);
}
}
printf("%lld\n",aans);
}
return 0;
}