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 ...
随机推荐
- 【转载】DDD分层架构的三种模式
引言 在讨论DDD分层架构的模式之前,我们先一起回顾一下DDD和分层架构的相关知识. DDD DDD(Domain Driven Design,领域驱动设计)作为一种软件开发方法,它可以帮助我们设计高 ...
- 如何在grails2.3.x中的fork模式下进行调试?-【grails】
grails2.3.x中默认情况下运行模式被设置成了fork模式,在这种模式下,大家会发现设置了断点后无法进行中断.这是由于fork模式造成的,因为在fork模式下,JVM新起了一个进程,这样调试器就 ...
- ArcGIS 10开发迁移策略(待续)
1.更改 ESRI.ArcGIS.ADF 程序集 ArcGIS 10 中, ADF 程序集中的功能被分散到不同的程序集中,如果将 ArcGIS 9.3 下 开发的自定义组件迁移到 ArcGIS 10 ...
- Python_collections_deque双向队列
deque:创建一个双向队列 import collections collections.deque(['nihao','x']) x.append():在列表的右边添加 x.appendleft( ...
- nginx-fastcgi 反向代理
Nginx处理php页面 用fpm-server 基于fastcgi模块实现 Ngx_http_proxy_module 只能反代后端http server的主机 Ngx_fastcgi_prox ...
- log4j.xml 报告集成
等级: trace< debug<info<warn<error<fatal trace 追踪 deug: eclipse, Log4j配置 [1]从零开始 a). ...
- 函数防抖 debounce
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Codeforces 806 D. Perishable Roads Dijkstra
原文链接https://www.cnblogs.com/zhouzhendong/p/CF806D.html 题目传送门 - CF806D 题意 给定一个 n 个点的无向完全图,每一条边有一定的边权. ...
- 如何用 Python 模糊搜索文件
一.我的文件在哪里? 1.告诉计算机文件在哪 使用路径描述位置 绝对路径——从根目录写到底 内置模块OS 路径 目录 文件 其他系统操作 2.描述文件的特征 用条件判断来筛选 3.对比后打印文件名 用 ...
- 【JavaScript】对象
No1: typeof操作符获取对象的类型 null的类型是object,Array的类型也是object,如果我们用typeof将无法区分出null.Array和通常意义上的object——{}. ...