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

InputInput 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. 
OutputFor 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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; struct De
{
int a,k;
};
De ch[]; int main()
{
int n,sum;
while(scanf("%d",&n) && n>=)
{
sum=;
for(int i=;i<n;i++)
scanf("%d %d",&ch[i].a,&ch[i].k),sum+=ch[i].a*ch[i].k;
int fb[];
memset(fb,,sizeof(fb));
for(int i=; i<n; i++)
for(int h=;h<ch[i].k;h++)
for(int j=sum/;j>=ch[i].a;j--)
fb[j]=max(fb[j],fb[j-ch[i].a]+ch[i].a);
printf("%d %d\n",sum-fb[sum/],fb[sum/]);
}
return ;
}

B - 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

    Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe ...

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

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

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

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

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

  6. Big Event in HDU[HDU1171]

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

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

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

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

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

  9. hdu1171 Big Event in HDU 01-背包

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

  10. HDU1171-Big Event in HDU

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

随机推荐

  1. python--第十七天总结(Django)

    基本配置 一.创建django程序 终端命令:django-admin startproject sitename IDE创建Django程序时,本质上都是自动执行上述命令 其他常用命令: pytho ...

  2. 自己测试项目中的log4j配置

    日志生成的位置在项目名下 主要记录的是这样配置,日志的生成的地方 下边是配置文件的内容 log4j.rootLogger=WARN, stdout, file log4j.appender.stdou ...

  3. gerapy 实现自动化部署

    1 安装 2 在需要部署的目录下运行 gerapy init 会在当前目录下生成一个gerapy目录,并在gerapy目录下有一个projects 目录 3 切换到gerapy 目录 cd gerap ...

  4. Excel uploading date format

    if l_wa_field-value eq 'ZFIRST_REQ_DATE'. clear lv_length. lv_length = strlen( l_wa_excel-value ). c ...

  5. http/2.0与http/1.1的区别

    http/2是http协议自1999年http1.1发布后的首个更新  主要基于SPDY协议 2.0  采用二进制 而不是文本格式 完全多路复用 而不是有序并阻塞的   只需要一个连接即可实现并行 使 ...

  6. koa中间件

    koa是Express的下一代基于node的web框架  目前有1.x和2.0两个版本 1. Express Express是第一代最流行的web框架  它对node.js的http进行了封装 Exp ...

  7. C#导入c++ dll报找不到dll文件 masm32调用c++类库

    最近需要在C#下调用一个c++ dll库,不管怎样dllimport就是报错找不到该dll文件,路径.函数名称.参数.dllimport参数逐个检查确认无误也无济于事,无奈想用其他语言调用试试,由于是 ...

  8. 使用idea的springboot项目出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    参考: https://www.cnblogs.com/lfm601508022/p/InvalidBoundStatement.html https://blog.csdn.net/xsggsx/a ...

  9. stm32定时器时钟以及中间对齐模式

    在永磁同步电机的控制中,需要对电机的三相定子施加一定的电压,才能控制电机转动.现在用的较多的是SVPWM(SVPWM的具体原理会在后面另写一篇博客说明),要想产生SVPWM波形,需要控制的三相电压呈如 ...

  10. MySQL数据库开发常见问题及几点优化!

    从一下三个方面考虑: 库表设计 慢 SQL 问题 误操作.程序 bug 时怎么办 一.库表设计 1.1.引擎选择 在 MySQL5.1 中,引入了新的插件式存储引擎体系结构,允许将存储引擎加载到正在运 ...