日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HDOJ 1171 Big Event in HDU

發布時間:2025/3/20 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。