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.

InputMultiple 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

OutputYour 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 种副武器, 同时每种武器都有 k 个权值,询问上面所给的目标式子中的最大收益
思路分析 : 考虑一下绝对值的性质, a-b 的绝对值等于 a-b 或者 -a+b , 并且题目所给的 k <= 5, 显然这里我们可以二进制去枚举,记录最大值即可
代码示例:
#define ll long long
const ll maxn = 1e5+5; ll n, m, k;
ll a[maxn][10], b[maxn][10];
ll sa[50], sb[50]; void init() {
ll f = 1;
for(ll i = 1; i <= k; i++) f *= 2;
memset(sa, 0x8f, sizeof(sa)); memset(sb, 0x8f, sizeof(sb));
//printf("++ %lld \n", sa[0]);
for(ll i = 1; i <= n; i++){
for(ll state = 0; state < f; state++){
ll sum = 0;
for(ll j = 0; j < k; j++){
if (state & (1<<j)) sum += a[i][j+1];
else sum -= a[i][j+1];
}
sa[state] = max(sa[state], sum+a[i][0]);
}
} for(ll i = 1; i <= m; i++){
for(ll state = 0; state < f; state++){
ll sum = 0;
for(ll j = 0; j < k; j++){
if (state & (1<<j)) sum += b[i][j+1];
else sum -= b[i][j+1];
}
sb[state] = max(sb[state], sum+b[i][0]);
}
}
} void solve() {
ll num = 1<<k;
ll ans = 0x8f;
for(ll i = 0; i < num; i++){
ll pp = num-1-i; ans = max(ans, sa[i]+sb[pp]);
}
printf("%lld\n", ans);
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll t; cin >> t;
while(t--){
scanf("%lld%lld%lld", &n, &m, &k);
for(ll i = 1; i <= n; i++){
for(ll j = 0; j <= k; j++){
scanf("%lld", &a[i][j]);
}
}
for(ll i = 1; i <= m; i++){
for(ll j = 0; j <= k; j++){
scanf("%lld", &b[i][j]);
}
}
init();
solve();
}
return 0;
}

状态压缩 hdu #10的更多相关文章

  1. 状态压缩 HDU 3182

    t组数据 n个汉堡 e的能量 接下来的2行 val    n个 得到的权 cost  n个 花去的能量 接下来n行 每行一个q  q个数字 代表这类汉堡做好要的前提  每个汉堡只能用一次 #inclu ...

  2. 状态压缩 HDU 1565

    多组数据 给你一个n*n的矩阵 不能相邻的取数 上下左右 求最大的和 #include<stdio.h> #include<algorithm> #include<str ...

  3. 状态压缩 HDU 3091

    多组数据 n个点m条边 求有几个经过所有的点的环 最好用__int64 #include<stdio.h> #include<algorithm> #include<st ...

  4. HDU 3605:Escape(最大流+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

  5. ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩

    HDU 5418 Victor and World Time Limit:2000MS     Memory Limit:131072KB     64bit IO Format:%I64d & ...

  6. HDU 4511 (AC自动机+状态压缩DP)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...

  7. hdu 2825(ac自动机+状态压缩dp)

    题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...

  8. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  9. hdu 4057 AC自己主动机+状态压缩dp

    http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...

随机推荐

  1. Python--day60--建立第一个Djiango项目

  2. Python--day61--Django的ORM

    下载驱动

  3. java 泛型接口和方法

    java5后,可以声明泛型接口,声明方式和声明泛型类是一样的. public interface IDAO<T>{} 泛型接口子类有两种方式: 直接在子类后申明泛型: 在子类实现的接口中给 ...

  4. Character.digit()的意义

    最近在阅读Integet.parseInt()源码时,遇到了Character.digit()这个方法,以前没有遇到过,更没使用过,这里查了资料就记录一下. 官方说法是: java.lang.Char ...

  5. H3C 链路聚合分类

  6. background:url(./images.png) no-repeat 0 center的用法

    background:url(./images.png) no-repeat 0 center; //图像地址 不重复 水平位置0 垂直位置居中 background:url(./images.png ...

  7. 有状态无状态回话bean

    1.有状态(Stateful) 可以在不同的方法调用间保持针对各个客户端的状态 与客户端的联系必须被维持,这样做开销要大一些 有状态也可以这样理解,它存在存储能力,也就是说至少有一个属性来标识它目前的 ...

  8. 【2016常州一中夏令营Day4】

    小 W 走迷宫[问题描述]小 W 被小 M 困在了一个方格矩阵迷宫里,矩阵边界在无穷远处,我们做出如下的假设:a. 每走一步时,只能从当前方格移动一格,走到某个相邻的方格上:b. 走过的格子立即塌陷无 ...

  9. python3中map函数

    map函数是Python里面比较重要的函数 map函数后面必须接的是序列(元组/列表/字符串) 在python2中执行一些语句 >>> map(str,[1,2,3,4]) ['1' ...

  10. C语言中的符号总结

    1.注释符号                     //和/* ...*/ 2.续行符号                      \ 3.转义符号                     常用:\ ...