# Problem S

##### Total Submission(s) : 116   Accepted Submission(s) : 46
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.<br>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&lt;N&lt;1000) kinds of facilities (different value, different kinds).<br>

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.<br>A test case starting with a negative integer terminates input and this test case is not to be processed.<br>

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

Sample Input
2 10 1 20 1 3 10 1 20 2 30 1 -1

Sample Output
20 10 40 40

如今,我们都知道,计算机学院二是最大的部门。但是,也许你不知道曾经分成计算机学院计算机学院和软件学院在2002年。< br >二分裂绝对是一个大事件!与此同时,这是一件麻烦的事。所有设备必须平分。首先,所有设施评估,和两个设施被认为是相同的,如果他们有相同的值。假设有N(0 & lt;N<1000)类型的设施。

这个是以前做的，思路有点遗忘，总的来说用一个数储存下来总价值，用一个累加数组记录n的值，再加上状态转移方程“dp[j]=max(dp[j],dp[j-a[i]]+a[i]);”就ok了。。

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int t,n,m,i,j,k,sum;
int dp[100001];
int a[100001];
while(cin>>t&&t>=0)
{
memset(dp,0,sizeof(dp));
sum=0;
k=0;
for(i=0;i<t;i++)
{
cin>>n>>m;
sum+=n*m;
for(j=0;j<m;j++)
{
a[k++]=n;
}
}
for(i=0;i<k;i++)
{
for(j=sum/2;j>=a[i];j--)
{
dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
}
}
cout<<sum-dp[sum/2]<<" "<<dp[sum/2]<<endl;
}
return 0;
}


05-25 119

04-30 152

10-23 882

04-02 223

12-23 292

#### EXCEL自动填充平分库存的问题

2017年12月14日 17KB 下载

05-24 103

05-18 188

05-25 140

05-26 114