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. Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)

    传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...

  2. cfp大纲

    AFP基础知识 本章共14个考点,考试考15分左右. 本章重点: .职业道德准则 .家庭财务分析:净值的计算.储蓄的计算 .简单的财务比率分析 .金融理财和法律:企业组织形式.夫妻公共财产制度.财产分 ...

  3. Leecoder466 Count The Repetitons

    Leecoder466 Count The Repetitons 题目大意 定义\([s,n]\)为连续\(n\)个串\(s\)构成的串 现在给定\(s_1,n_1,s_2,n_2\),求最大的\(m ...

  4. Spring Security 学习笔记-securityContext过滤器过滤链学习

    web.xml配置委托代理filter,filter-name默认与filter bean的名字保持一致. <filter> <filter-name>springSecuri ...

  5. Curator源码阅读 - ConnectionState的管理与监听

    看看Curator框架 为实现对 连接状态ConnectionState的监听,都是怎么构造框架的.后面我们也可以应用到业务的各种监听中. Curator2.13实现 接口 Listener List ...

  6. 网摘-获取屏幕dc并且将其画面显示在窗体中

    获取屏幕dc并且将其画面显示在窗体中 HWND hWnd = ::GetDesktopWindow();//获得屏幕的HWND. HDC hScreenDC = ::GetDC(hWnd);   // ...

  7. Android Library的依赖方式及发布(转)

    还是那句老话,好记性不然烂笔头,在此整理 Android Studio 依赖相关 以及 如何发布项目到 JCenter Android Studio 添加依赖Module 依赖module 依赖是指在 ...

  8. 【原创】(十四)Linux内存管理之page fault处理

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  9. HolidayFileDisPersonViewList.js中的一些基础

    1,CSS display 属性 使段落生出行内框: p.inline { display:inline; } none 此元素不会被显示 详细介绍:  http://www.w3school.com ...

  10. Centos 7.5安装 Redis 5.0.0

    1 我的环境  1.1 linux(腾讯云) CentOS Linux release 7.5.1804 (Core)  1.2 Redis Redis 5.0.0 2 下载 官网 官网下载地址 3 ...