hdu1171 Big Event in HDU(多重背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1171
多重背包题目不难,但是有些点不能漏或错。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 1e9
typedef long long ll;
using namespace std;
int n, a[], b[], dp[];
int main()
{
IO;
while(cin >> n){
memset(dp, , sizeof(dp)); //不要忘了初始化
if(n < ) break;
int sum = ;
for(int i = ; i < n; i++){
cin >> a[i] >> b[i];
sum += a[i]*b[i];
}
int half=sum/;
for(int i = ; i < n; i++){
for(int k = ; k < b[i]; k++){//多重背包循环是在这里,而不是下面
for(int j = half; j >= a[i]; j--){//sum会超时
dp[j] = max(dp[j], dp[j-a[i]]+a[i]);
}
}
}
cout << sum-dp[half] << " " << dp[half] << endl;
}
return ;
}
hdu1171 Big Event in HDU(多重背包)的更多相关文章
- HDU 1171 Big Event in HDU 多重背包二进制优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...
- HDU - 1171 Big Event in HDU 多重背包
B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...
- HDU 1171 Big Event in HDU (多重背包变形)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1171:Big Event in HDU(多重背包分析)
通过分析,要使A>=B并且差值最小.所以只要使sum/2的容量下,B最大就Ok了 #include<iostream> #include<cstdio> #include ...
- HDU-1171 Big Event in HDU(生成函数/背包dp)
题意 给出物品种类,物品单价,每种物品的数量,尽可能把其分成价值相等的两部分. 思路 背包的思路显然是用一半总价值当作背包容量. 生成函数则是构造形如$1+x^{w[i]}+x^{2*w[i]}+.. ...
- hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu1171 Big Event in HDU 01-背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...
- HUD 1171 Big Event in HDU(01背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
随机推荐
- bzoj4059
题解: 还是一道不错的题目 首先它要求每个区间都满足要求,所以我们很容易想到将它映射到二维平面上 然后我们算出每个数的前驱以及后继li,ri 那么第一维是li-i,第二维是i-ri的区间就是合法的,同 ...
- 网页前端 html js 相关
1.注释 1.1HTML 注释 http://www.w3school.com.cn/html/html_comments.asp 注释标签 <!-- 与 --> 用于在 HTML 插入注 ...
- 【Android】android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
最终效果图,点击save会保存到文件中,点击show会从文件中读取出内容并显示. main.xml <?xml version="1.0" encoding="ut ...
- python全栈开发day77-博客主页
1.文章分类 2.标签 3.归档 1) MySQL的日期格式化函数 DATE_FORMAT(字段名,格式) 2) Django ORM中如何执行SQL原生语句 (1) models.Article.o ...
- Windows 系统判断MD5 值的办法
Linux 系统的文件要传到Windows系统里面,传输过程中网络不稳定,为了判断文件是否完整传输,所以就用md5的方式判断是否同一个文件 Linux系统 [root@augusite ~]# md5 ...
- jenkins(5): jenkins邮件报警配置
参考: https://blog.csdn.net/u013066244/article/details/78665075 1. 使用 增强版的邮件通知 1.1 安装插件 1.2. 系统配置 ...
- js,JQuery 生成二维码
代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- BZOJ3295 [Cqoi2011]动态逆序对 分治 树状数组
原文链接http://www.cnblogs.com/zhouzhendong/p/8678185.html 题目传送门 - BZOJ3295 题意 对于序列$A$,它的逆序对数定义为满足$i< ...
- JDK5的新特性之可变参数&Arrays.asList()方法
[代码] package com.hxl; import java.util.Arrays; import java.util.List; public class Test { public sta ...
- IDEA添加源码包
1.在项目中选中左上角的File--->Project Structure 2.选择需要添加的源码包 3.源码已经加入