欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

HDOJ 1171 Big Event in HDU

发布时间:2025/3/20 编程问答 68 豆豆
生活随笔 收集整理的这篇文章主要介绍了 HDOJ 1171 Big Event in HDU 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

背包模版:

Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17006    Accepted Submission(s): 5991


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).

 

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.

 

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 2 10 1 20 1 3 10 1 20 2 30 1 -1

 

Sample Output 20 10 40 40

 

Author lcy 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int v; 8 int dp[333333]; 9 10 void zpack(int *a,int c,int w) 11 { 12 for(int i=v;i>=c;i--) 13 a[i]=max(a[i],a[i-c]+w); 14 } 15 16 void cpack(int *a,int c,int w) 17 { 18 for(int i=c;i<=v;i++) 19 a[i]=max(a[i],a[i-c]+w); 20 } 21 22 void multipack(int *a,int c,int w,int m) 23 { 24 if(c*m>=v) 25 { 26 cpack(a,c,w); 27 return ; 28 } 29 30 int k=1; 31 while(k<m) 32 { 33 zpack(a,k*c,k*w); 34 m-=k; 35 k*=2; 36 } 37 38 zpack(a,m*c,m*w); 39 } 40 41 int c[100]; 42 int m[100]; 43 44 int main() 45 { 46 int n; 47 while(scanf("%d",&n)&&n>0) 48 { 49 memset(c,0,sizeof(c)); 50 memset(m,0,sizeof(m)); 51 memset(dp,0,sizeof(dp)); 52 53 int sum=0; 54 for(int i=0;i<n;i++) 55 { 56 scanf("%d%d",&c[i],&m[i]); 57 sum+=c[i]*m[i]; 58 } 59 v=sum/2; 60 for(int i=0;i<n;i++) 61 multipack(dp,c[i],c[i],m[i]); 62 63 printf("%d %d\n",sum-dp[v],dp[v]); 64 65 } 66 67 return 0; 68 }

 

 

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/27/3102820.html

总结

以上是生活随笔为你收集整理的HDOJ 1171 Big Event in HDU的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。