状态压缩 hdu #10
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.
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的更多相关文章
- 状态压缩 HDU 3182
t组数据 n个汉堡 e的能量 接下来的2行 val n个 得到的权 cost n个 花去的能量 接下来n行 每行一个q q个数字 代表这类汉堡做好要的前提 每个汉堡只能用一次 #inclu ...
- 状态压缩 HDU 1565
多组数据 给你一个n*n的矩阵 不能相邻的取数 上下左右 求最大的和 #include<stdio.h> #include<algorithm> #include<str ...
- 状态压缩 HDU 3091
多组数据 n个点m条边 求有几个经过所有的点的环 最好用__int64 #include<stdio.h> #include<algorithm> #include<st ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- ACM: HDU 5418 Victor and World - Floyd算法+dp状态压缩
HDU 5418 Victor and World Time Limit:2000MS Memory Limit:131072KB 64bit IO Format:%I64d & ...
- HDU 4511 (AC自动机+状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...
- hdu 2825(ac自动机+状态压缩dp)
题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- hdu 4057 AC自己主动机+状态压缩dp
http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...
随机推荐
- [转]Win10下安装Linux子系统
工作以来一直DotNet系偏C/S, 接触Web开发的时间也不长, 现在主要偏向Web全栈方向, 一直对Linux系统心生向往, 夜深了娃睡了, 打开老旧的笔记本来折腾一下. 准备工作 控制面板 &g ...
- webpack学习(四)配置plugins
1 plugins是什么??? 如果学过vue和react肯定知道生命周期函数,而生命周期函数实际上就是当程序运行在某个时刻一定会发生的函数. plugins其实也是如此,我们在项目中配置相应的plu ...
- 2018-8-10-dot-net-core-使用-IPC-进程通信
title author date CreateTime categories dot net core 使用 IPC 进程通信 lindexi 2018-08-10 19:16:52 +0800 2 ...
- 2019-10-18-WPF-高速书写-StylusPlugIn-原理
title author date CreateTime categories WPF 高速书写 StylusPlugIn 原理 lindexi 2019-10-18 21:23:46 +0800 2 ...
- SDNU ACM-ICPC 2019 Competition For the End of Term(12-15)山师停训赛题解
马鸿儒 目前已补:01 03 06 07 08 09 10 11目前未补:02 04 05 12 苏用 1582.柳予欣的舔狗行为 1587.柳予欣的女朋友们在分享水果 1585.柳予欣和她女朋友的购 ...
- 小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题
scroll-view 中的需要滑动的元素不可以用 float 浮动:
- H3C查看系统启动配置文件
- 【2016常州一中夏令营Day6】
小 W 算树[问题描述]山有苞棣,隰有树檖.未见君子,忧心如醉~小 W 养了一棵有 N 个点的无根树,由于小 M 最喜欢二叉树了,为了讨小 M 欢喜,小 W想知道有多少个点作为根后,这棵树是一棵二叉树 ...
- java 环境 笔记
1. 下载idea https://blog.csdn.net/yl1712725180/article/details/80309862 破解方法: 针对20 ...
- 红米K20 Pro 传感器失效解决方案
最近把Redmi K20 Pro升级到了安卓Q,用了几天,不好用,总是提示屏幕前方有遮挡,于是刷回了安卓9,但是发现重力感应传感器失效了,屏幕不会随这方向转,导航的时候看起来很难受. 网上查了一下,要 ...