Big Event in HDU
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
HDU 1171
Appoint description:
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
#include <cstdio>
#include <cstring>
#define N 55
#define M 300000
#define CRL(a, b) memset(a, b, sizeof(a))
int n, typ[N], fee[N], sum, mid;
bool num1[M], num2[M];
void getnum()
{
CRL(num1, 0);
CRL(num2, 0);
num1[0] = 1;
for(int i=1; i<=n; i++)
{
for(int j=0; j<=mid; j++)
{
for(int k=0; k<=fee[i]*typ[i] && j+k<=mid; k+=fee[i])
{
if(num1[j])
{
num2[j+k] = 1;
}
}
}
for(int j=0; j<=mid; j++)
{
num1[j] = num2[j];
num2[j] = 0;
}
}
}
int main()
{
while(scanf("%d", &n) && n >= 0)
{
sum = 0;
for(int i=1; i<=n; i++)
{
scanf("%d%d", &fee[i], &typ[i]);
sum += typ[i] * fee[i];
}
mid = sum >> 1;//讨论一半的组合就好了
getnum();
int ans = 0;
for(int i=1; i<=mid; i++)
{
if(num1[i])//取最大的组合
{
ans = i;
}
}
printf("%d %d\n", sum-ans, ans);
}
return 0;
}