背包--HDU 1171 Big Event in HDU
2017-11-05 11:54
375 查看
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44535 Accepted Submission(s): 15321
[align=left]Problem Description[/align]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).
[align=left]Input[/align]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.
[align=left]Output[/align]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.
[align=left]Sample Input[/align]2
10 1
20 1
3
10 1
20 2
30 1
-1
[align=left]Sample Output[/align]
20 10 40 40[align=left]
[/align][align=left]代码:[/align][align=left]#include<stdio.h>
#include<string.h>
int main()
{
int i,j,n,m,m1,x,pr[5005],t,f[250005];
while(scanf("%d",&n)&&n!=-1){
j=0;
m=0;
memset(f,0,sizeof(f));
memset(pr,0,sizeof(pr));
for(i=0;i<n;i++){
scanf("%d%d",&x,&t);
m+=x*t;
while(t--)
pr[j++]=x;
}
m1=m/2;
for(t=0;t<j;t++)
for(i=m1;i>=pr[t];i--){
f[i]=f[i]>(f[i-pr[t]]+(pr[t]))?f[i]:(f[i-pr[t]]+(pr[t]));
}
printf("%d %d\n",m-f[m1],f[m1]);
}
return 0;
}
[/align][align=left]我肯定是个傻逼,一直用判断条件n!=-1作为结束循环的条件,看别人题解才发现原来是负数就不行,眼瞎了
[/align]
相关文章推荐
- hdu 1171 Big Event in HDU(多重背包可行性)
- HDU 1171 Big Event in HDU (多重背包+单调队列优化)
- HDU 1171 Big Event in HDU【多重背包||母函数】
- HDU 1171 Big Event in HDU(多重背包)
- HDU 1171 Big Event In HDU 背包拆分
- HDU-1171 Big Event in HDU 背包
- hdu 1171 Big Event in HDU(多重背包)
- 暑期dp46道(32)--hdoj 1171 Big Event in HDU 多重背包:
- [HDU 1171 Big Event in HDU]背包
- HDU 1171 Big Event in HDU 多重背包二进制优化
- HDU 1171 Big Event in HDU (多重背包变形)
- HDU 1171 Big Event in HDU(背包)
- 【HDU 1171】【背包DP 或者 母函数】Big Event in HDU【有n样物品,每样物品价值是v,件数是m。尽量把这些物品分成两堆使得两边总价值最接近】
- Big Event in HDU (HDU_1171) 01背包
- HDU 1171 Big Event in HDU 多重背包 数分一半
- HDU 1171 Big Event in HDU(多重背包)
- hdu 1171 - Big Event in HDU(完全背包)
- HDU 1171 Big Event in HDU (由01背包演变的水题)
- HDU-1171 - Big Event in HDU - 01背包
- HDU/HDOJ 1171 Big Event in HDU 01背包、多重背包、母函数