HDU 1171 Big Event in HDU (多重背包)

原创 2018年04月17日 19:06:52

Big Event in HDU

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


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
之前由于题目描述还对相同价值的设施个数进行了归纳,也提交对了,看别人的才发现不用处理,思想和 邮票分你一半一题 一样
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int p[55];
int c[55];
int dp[250050];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		if(n<0) break;
		int sum=0;
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&c[i],&p[i]);
			sum+=p[i]*c[i];
		}
		
		for(int i=0;i<n;i++)
	    {
	        for(int j=1;j<=p[i];j++)//每个的最多数 
	        {
	            for(int k=sum/2;k>=c[i];k--)//01背包 
	            	if(dp[k]<dp[k-c[i]]+c[i])
	        	    	dp[k]=dp[k-c[i]]+c[i];
        	}
		}
		printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
	}
	return 0;
	
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BBHHTT/article/details/79979147

uCOS2的events事件源码分析-第4季第5部分

-
  • 1970年01月01日 08:00

HDU 1171 Big Event in HDU (母函数)

题意:有n样物品,每样物品价值是v,件数是m。尽量把这些物品分成两堆使得两边总价值最接近。输出分得的两堆各自的价值。 利用母函数法来解决,因为分成两堆,而两堆中较小的一堆最大为所有物品总价值量的一半,...
  • IAccepted
  • IAccepted
  • 2014-04-28 16:42:39
  • 3003

杭电1171Big Event in HDU

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other...
  • z8110
  • z8110
  • 2015-09-18 18:39:56
  • 302

HDU 1171 Big Event in HDU(母函数||DP)

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other...
  • jk13171217
  • jk13171217
  • 2014-07-30 16:43:31
  • 665

hdoj 1171 Big Event in HDU 【母函数】【01背包】

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others...
  • chenzhenyu123456
  • chenzhenyu123456
  • 2015-04-22 22:17:57
  • 531

Big Event in HDU(杭电1171)(多重背包)和(母函数)两种解法

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others...
  • hdd871532887
  • hdd871532887
  • 2014-11-19 20:35:31
  • 639

杭电ACM hdu 1171 Big Event in HDU 解题报告(母函数)

出处: Problem Description Nowadays, we all know that Computer College is the biggest department in HDU...
  • u012077163
  • u012077163
  • 2013-11-30 16:36:15
  • 2125

hdu 1171 Big Event in HDU 母函数解法。。以后再来用背包A一下

Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu...
  • Lionel_D
  • Lionel_D
  • 2015-03-04 16:50:30
  • 654

hdu1171Big Event in HDU(母函数)

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other...
  • bokzmm
  • bokzmm
  • 2015-12-09 19:22:23
  • 152

杭电1171 Big Event in HDU(母函数+多重背包解法)

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other...
  • u013634213
  • u013634213
  • 2014-08-24 02:02:51
  • 974
收藏助手
不良信息举报
您举报文章:HDU 1171 Big Event in HDU (多重背包)
举报原因:
原因补充:

(最多只允许输入30个字)