状态压缩 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 ...
随机推荐
- HDU 6623"Minimal Power of Prime"(数学)
传送门 •题意 给你一个大于 1 的正整数 n: 它可以分解成不同的质因子的幂的乘积的形式,问这些质因子的幂中,最小的幂是多少. •题解 定义 $ans$ 表示最终答案: ①如果 $ans \ge 5 ...
- vue element UI el-table 表格调整行高的处理方法
这是我在工作项目中遇到的问题,我想将标记处下方的表格高度调低一点,也就是想实现下面的这个效果: 代码调整如下: 说明: 缩小:行高到一定程度之后便不能缩小. 好像最小35px.各位可以试一下. 升高: ...
- H3C查看系统启动配置文件
- Linux 内核bin+attribute 结构二进制属性
sysfs 惯例调用所有属性来包含一个单个的人可读文本格式的值. 就是说, 只是偶然地很 少需要来创建能够处理大量二进制数据的属性. 这个需要真正地只出现在必须传递数据, 不可动地, 在用户空间和设备 ...
- Linux 内核kobject 缺省属性
当被创建时, 每个 kobject 被给定一套缺省属性. 这些属性通过 kobj_type 结构来指定. 这个结构, 记住, 看来如此: struct kobj_type { void (*relea ...
- 前端js页面跳转
window.location.Reload() //刷新当前页面self.location=document.referrer;通过Request Headers中Referer获得上个页面的地址并 ...
- Java 学习笔记(4)——面向对象
现在一般的语言都支持面向对象,而java更是将其做到很过分的地步,java是强制使用面向对象的写法,简单的写一个Hello Word都必须使用面向对象,这也是当初我很反感它的一点,当然现在也是很不喜欢 ...
- VRChat模型制作及上传总篇(201912)
1.视频资源及软件插件模型资源: Kodoku-shi :https://www.bilibili.com/video/av20097333(自己目前找到讲的最详细的教程,但是blender减免部分貌 ...
- 转载:通过监控Nginx日志来实时屏蔽高频恶意访问的IP
通过监控Nginx日志来实时屏蔽高频恶意访问的IP 目前在我的VPS上主要通过两种方式来限制ip的访问次数. 通过Nginx的limit_req配置来限制同一ip在一分钟内的访问次数 通过Ngin ...
- 20191121-3 Final阶段贡献分配规则
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/10063 ”组长”组final阶段贡献分分配规则 组里五位成员分别有入团队 ...