杭电1171Big Event in HDU(01背包)
来源:互联网 发布:淘宝店招装修 编辑:程序博客网 时间:2024/06/05 17:46
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33050 Accepted Submission(s): 11527
Problem Description
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
Author
lcy
Recommend
We have carefully selected several similar problems for you: 2159 2844 1087 2191 11
为了保持俩个学院竟可能的相等,则sum/2;#include<stdio.h>
#include<string.h>#include<algorithm>
using namespace std;
int main()
{
int n,v,m,i,j,l,sum;
int value[5010],dp[250010];
while(~scanf("%d",&n))
{
if(n<0)
break;
sum=l=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&v,&m);
sum+=v*m;
while(m--)
value[l++]=v;
}
memset(dp,0,sizeof(dp));
for(i=0;i<l;i++)
for(j=sum/2;j>=value[i];j--)
dp[j]=max(dp[j],dp[j-value[i]]+value[i]);
printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
}
return 0;
}
0 0
- 杭电1171Big Event in HDU(01背包)
- 杭电-1171 Big Event in HDU(完全背包转换01背包)
- 【杭电oj】1171 - Big Event in HDU(01背包)
- 杭电1171 Big Event in HDU(母函数+多重背包解法)
- 杭电acm 1171Big Event in HDU(0-1背包)
- 杭电 1171 Big Event in HDU
- 杭电1171-Big Event in HDU
- 杭电1171 Big Event in HDU
- 杭电1171Big Event in HDU
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包问题)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU (01背包)
- HDU 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包变形)
- HDU 1171 Big Event in HDU (DP--01背包)
- hibernate 4 映射组件属性 自定义类型
- 获取文件数组和文件夹数组
- java下载文件
- 配置树莓派3和局域网NTP服务器实现内网时间校准
- Poj 2010 Moo University - Financial Aid【优先队列+神技巧】
- 杭电1171Big Event in HDU(01背包)
- C++STL优先队列小结
- 获取系统的当前信息
- SOLR在电商中的基本应用
- codevs1007
- 正确处理浏览器在下载文件时HTTP头的编码问题(Content-Disposition)
- PTA 数列求和加强版
- tab选项卡(解决问题 i总是最后一个)
- 关于Untiy中数值传递的问题