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 好久不刷题了,看到这个题一点思路也没有。后来想了一下,其实不难。把一组数,分解为和尽量相等的2组数。
看作01背包问题,背包容量为sum/2,求怎么组合可以最大可能的接近sum/2.
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int val[*+];
int dp[];
int max(int a,int b)
{
if(a>=b) return a;
else return b;
}
int main()
{ int n;
while(~scanf("%d",&n)&&n>)
{
memset(dp,,sizeof(dp));
int sum=;
int num=;
for(int i=;i<n;i++)
{
int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
while(tmp2>)
{
val[num++]=tmp1;
sum+=tmp1;
tmp2--;
}
}
for(int i=;i<num;i++)
{
for(int j=sum/;j>=val[i];j--)
{
dp[j]=max(dp[j-val[i]]+val[i],dp[j]);
}
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}

Big Event in HDU的更多相关文章

  1. HDU-1171 Big Event in HDU

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  2. Big Event in HDU(HDU1171)可用背包和母函数求解

    Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三 ...

  3. 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  5. Big Event in HDU[HDU1171]

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

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

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  9. HDU1171-Big Event in HDU

    描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...

随机推荐

  1. python之集合,函数,装饰器

    本节主要内容如下: 1. set集合 2. 函数 -- 自定义函数 -- 内置函数 3. 装饰器 一. set 集合: 一个无序且不重复的序列. tuple算是list和str的杂合(杂交的都有自己的 ...

  2. CAD2010中文版安装问题记录

    CAD2010中文版安装到简体中文语言包的时候提示[错误1606无法访问网络位置setup],直接打开cad2010 提示 [adui18res.dll not found]: 首先,进入注册表(re ...

  3. Apache 的 httpd.conf 详解

    ServerRoot “/usr/local“ ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是 ...

  4. Mysql之高可用

    使用缓存Memcache, 1,可使用Hash算法由客户端决定路由到哪个Memcache服务器上:客户端完全不用关心数据存储在哪个Memcache服务器上:完全隔离了客户端与服务端:由于是Hash,在 ...

  5. mybatis 学习!

    参考链接 http://www.mybatis.org/spring/zh/mappers.html http://www.cnblogs.com/fangjian0423/p/spring-myba ...

  6. Lattice Diamond 学习之编译、检查和设置约束

    在新建工程以及完成代码的输入之后.则就要进行编译,并检测错误. 一. Generate Hierarchy(产生层次结构). 1. 点击Generate Hierarchy 图标或者Design -- ...

  7. .NET开发工具之Excel导出公共类

    来源:Pino晨 链接:cnblogs.com/chenxygx/p/5954870.html 说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Ex ...

  8. acpi参考网站

    1.acpi官网: http://www.acpi.info/

  9. 在Win7 64位注册ActiveX控件

    首先必须以管理员身份运行cmd.exe,即在cmd.exe右键选择以管理员身份运行.    目前共有两个存在网络盘的文件需要注册,一个dll,一个ocx.    开始时将两个文件都拷贝到c:\wind ...

  10. markdown编辑器使用建议

    markdown在线编辑器: https://stackedit.io/editorhttp://dillinger.io/ windows 下建议使用 MarkdownPad linux 下建议使用 ...