题目描述
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.
输入
Multiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for each group, the first line have three positive integers n, m, K.
then, the next n line will describe n Main Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
then, the next m line will describe m Secondary Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
There is a blank line before each groups of data.
T<=100, n<=100000, m<=100000, K<=5, 0<=S<=1e9, |x[i]|<=1e9, sum of (n+m)<=300000
输出
Your output should include T lines, for each line, output the maximum evaluation for the corresponding datum.
样例输入
2 2 2 1 0 233 0 666 0 123 0 456 2 2 1 100 0 1000 100 1000 100 100 0
样例输出
543 2000
你正在打cs,有n把主武器,m把副武器,没把武器的威力为s,除此,每把武器有k个性能指标,现在你要各选择一把武器,使得
公式的值最大。
公式的后半部分是一个曼哈顿距离,所以,我们尝试去枚举所有状态,对于每把武器,我们只有取和不取的状态,对于每种状态,武器性能的贡献值有加和减两种状态,即k纬,因为k很小,所以位运算枚举即可。
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
int s;
int x[6];
}Main[100050],Second[100050];
int main()
{
int t,n,m,k;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&Main[i].s);
for(int j=1;j<=k;j++)
{
scanf("%d",&Main[i].x[j]);
}
}
for(int i=1;i<=m;i++)
{
scanf("%d",&Second[i].s);
for(int j=1;j<=k;j++)
{
scanf("%d",&Second[i].x[j]);
}
}
int tt=(1<<k);
ll maxx[35];
for(int i=0;i<=34;i++)
{
maxx[i]=-1e17;
}
for(int i=0;i<tt;i++)
{
for(int j=1;j<=n;j++)
{
ll sum=Main[j].s;
for(int p=1;p<=k;p++)
{
if(i>>(p-1)&1)
{
sum+=Main[j].x[p];
}
else
{
sum-=Main[j].x[p];
}
}
maxx[i]=max(maxx[i],sum);
}
}
ll mbxx[35];
for(int i=0;i<=34;i++)
{
mbxx[i]=-1e17;
}
for(int i=0;i<tt;i++)
{
for(int j=1;j<=m;j++)
{
ll sum=Second[j].s;
for(int p=1;p<=k;p++)
{
if(i>>(p-1)&1)
{
sum-=Second[j].x[p];
}
else
{
sum+=Second[j].x[p];
}
}
mbxx[i]=max(mbxx[i],sum);
}
}
ll ans=0;
for(int i=0;i<tt;i++)
{
ans=max(ans,maxx[i]+mbxx[i]);
}
printf("%lld\n",ans);
}
return 0;
}