hdoj-1171-Big Event in HDU【动态规划】
来源:互联网 发布:网络大电影发行流程 编辑:程序博客网 时间:2024/06/15 15:37
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28852 Accepted Submission(s): 10143
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 2191 1114 1421
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[1000000];int dp[1000000];int cmp(int a,int b){return a>b;}int main(){int n;while(~scanf("%d",&n),n>0){int i,j,k=0,val,num,sum=0;for(i=1;i<=n;++i){scanf("%d%d",&val,&num);sum+=val*num;while(num--){a[++k]=val;}}double p=1.0*sum/2;sort(a+1,a+k+1,cmp);memset(dp,0,sizeof(dp));int maxn=0;for(i=1;i<=k;++i){ for(j=0;j<i;++j){ if(dp[j]+a[i]<=p) dp[i]=max(dp[i],dp[j]+a[i]); } maxn=max(maxn,dp[i]);}maxn=max(maxn,sum-maxn); printf("%d %d\n",maxn,sum-maxn);}return 0;}
0 0
- hdoj-1171-Big Event in HDU【动态规划】
- HDU 1171 Big Event in HDU 动态规划 多重背包
- hdu1171 Big Event in HDU 动态规划
- HDOJ 1171 Big Event in HDU
- HDOJ--1171--Big Event in HDU
- hdoj 1171Big Event in HDU【dp】
- HDOJ-1171 Big Event in HDU
- HDOJ 1171 Big Event in HDU
- hdoj-1171-Big Event in HDU
- hdoj-【1171 Big Event in HDU】
- HDOJ Big Event in HDU
- HDU1171-Big Event In HDU(母函数、动态规划)
- HDOJ 1171 Big Event in HDU解题报告
- hdoj 1171 Big Event in HDU(背包dp+母函数)
- HDOJ 1171 Big Event in HDU (多重背包) / (母函数)
- HDOJ题目1171Big Event in HDU(多重背包)
- 母函数之Big Event in HDU hdoj 1171
- HDOJ 1171 Big Event in HDU(多重背包)
- 指针操作一维数组
- 如何用Redis做LRU-Cache
- URAL 1900. Brainwashing Device(dp+输出路径)
- JS 基础 用法
- Touch
- hdoj-1171-Big Event in HDU【动态规划】
- JAVA 程序 对给定整数60,获取其16进制表现形式
- C++客户端 如何通过gsoap调用WebService接口(以及返回结果乱码解决办法)
- cosme大赏卸妆部门第二位:Peau Blanche卸妆水之体验报告
- java发送邮件(1)
- zoj 3612 ——Median
- 一行字符中寻找英文单词个数
- url
- 指纹识别的基本原理