[HDOJ1171]Big Event in HDU(01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171
许多有价值的物品,有重复。问如何将他们分成两堆,使两堆价值之差最小。
对价值求和,转换成01背包,做一次,相当于一堆选物品使得最接近一半。然后这个结果和用价值和作差的结果就是两堆的价值,此时价值只差最小。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n;
int v[];
int m;
int dp[maxn]; int main() {
// freopen("in", "r", stdin);
int vv, mm;
while(~scanf("%d", &n) && n >= ) {
memset(dp, , sizeof(dp));
memset(v, , sizeof(v));
m = ;
int half = ;
for(int i = ; i < n; i++) {
scanf("%d %d", &vv, &mm);
half += vv * mm;
while(mm--) v[m++] = vv;
}
for(int i = ; i <= m; i++) {
for(int j = half / ; j >= v[i]; j--) {
dp[j] = max(dp[j], dp[j-v[i]]+v[i]);
}
}
printf("%d %d\n", half-dp[half/], dp[half/]);
}
return ;
}
[HDOJ1171]Big Event in HDU(01背包)的更多相关文章
- hdu 1171 Big Event in HDU (01背包, 母函数)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HUD 1171 Big Event in HDU(01背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- 1171 Big Event in HDU 01背包
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...
- hdu1171Big Event in HDU(01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU(01背包)
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...
- Big Event in HDU(01背包)
/* 题意: 输入一个数n代表有n种物品, 接下来输入物品的价值和物品的个数: 然后将这些物品分成A B 两份,使A B的价值尽可能相等也就是尽量分的公平一些,如果无法使A B相等,那么就使A多一些: ...
- HDU 1171 Big Event in HDU(01背包)
题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++ ...
- hdoj1171 Big Event in HDU(01背包 || 多重背包)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意 老师有一个属性:价值(value).在学院里的老师共有n种价值,每一种价值value对应着 ...
- 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 ...
随机推荐
- 常用的Python字符串常量
下面是一些常用的Python字符串常量string.digits:包含0-9的字符串string.letters:包含所有大小写字母的字符串 string.lowercase:所有小写字母string ...
- 《深入浅出JavaScript》
第一章JS入门 第二章数据和判定常用的转义序列\b 回退 \f换页 \n换行 \r回车 \t制表符 \'单引 \"双引 \\反斜乘除求余的优先级相同,从左向右执行string对象indexO ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- 驱动笔记 - ioctl
#include <linux/ioctl.h> 定义命令 _IO(type,nr) 没有参数的命令 _IOR(type,nr,datatype) 从驱动中读数据 _IOW(type,nr ...
- Mysql 操作
MySQL命令行导出数据库:1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录如我输入的命令行:cd C:\Program Files\MySQL\MySQL Server ...
- 分布式数据存储-MySQL主从复制
前言 一.主从复制过程 MySQL的主从复制能力是通过三个线程来实现的,两个在Slave端的I/O和SQL两个线程,还有一个在Master端I/O线程: Binlog dump thread:Mast ...
- MySQL数据库优化总结
对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一般来说,要保证数据库的效率,要做好以下四个方面的工作:数 据库设计.sql语句优化.数据库参数配置.恰当的硬件资 ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- [你必须知道的.NET]第三十四回,object成员,不见了!
发布日期:2009.10.30 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 在.NET世界了,object是公认的造物主,其麾下的7大成员, ...
- [你必须知道的.NET]第三十一回,深入.NET 4.0之,从“新”展望
发布日期:2009.05.22 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. /// <summary> /// 本文开始,将以& ...