Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 40976 Accepted Submission(s): 14090

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

利用整除的性质,满足A is not less than B ,然后扩展背包数目,开始01背包

坑点就是看清题目中的dp数,数组要开大,否则会超时

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
int dp[300000];
int w[6000]; int main() {
int n;
while(scanf("%d",&n)==1&&n>=0) {
memset(dp,0,sizeof(dp));
// memset(w,0,sizeof(w));
int a,b;
int t=1;
int sum=0;
for(int i=1;i<=n;i++) {
scanf("%d%d",&a,&b);
sum+=a*b;
while(b--) {
w[t++]=a;
//sum+=a;
}
}
int m=sum/2;
for(int i=1;i<t;i++) {
for(int j=m;j>=w[i];j--) {
dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
}
}
printf("%d %d\n",sum-dp[m],dp[m]); } return 0;
}

HDU 1171 Big Event in HDU dp背包的更多相关文章

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

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

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

  3. HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】

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

  4. 题解报告:hdu 1171 Big Event in HDU(多重背包)

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

  5. HDU 1171 Big Event in HDU(01背包)

    题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...

  6. hdu 1171 Big Event in HDU (01背包, 母函数)

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

  7. HDU 1171 Big Event in HDU (动态规划、01背包)

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

  8. 【01背包】HDU 1171 Big Event in HDU

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

  9. HDU 1171 Big Event in HDU (多重背包变形)

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

随机推荐

  1. az nginx install and other

    Nginx     1◆ nginx install 源码:https://trac.nginx.org/nginx/browser   官网:http://www.nginx.org/       ...

  2. Win10系列:JavaScript 数据绑定

    使用数据绑定可以使页面中元素的属性值与数据源中的数据同步,其中数据源可以来自数据库.文件以及自定义的数据等.在常用的数据绑定方法中,简单对象绑定是将HTML元素与一个仅包含数据的简单对象相绑定,模板绑 ...

  3. Unity中Button按钮的触发监听事件

    第一种方式:需要把自己添加的Button按钮属性(Inspector)中的(Button)onclick添加方法. public void BtnCreteClick() { Debug.Log(&q ...

  4. 每天CSS学习之text-decoration

    text-decoration是CSS的一个属性,其作用是给文本装饰上划线.中间线.下划线或不装饰.其值如下所示: 1.none:不装饰任何线.该值是默认值.如下所示: p{ text-decorat ...

  5. VSTO:使用C#开发Excel、Word【5】

    <Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath >——By Eric C ...

  6. 5.6 C++重载下标操作符

    参考:http://www.weixueyuan.net/view/6384.html 总结: 下标操作符是必须要以类的成员函数的形式进行重载的.其在类中的声明格式如下:    返回类型 & ...

  7. MyEclipse和Eclipse

    Eclipse 分成3个子项目: ·平台Platform ·开发工具箱-Java Development Toolkit(JDT) ·外挂开发环境-Plug-in Development Enviro ...

  8. 创建自己的docker基础镜像

    1.下载镜像 centos7 docker pull centos: 2.创建容器加载镜像 docker run -i -t --name centos7 centos: docker run 参数详 ...

  9. POJ - 3252 A - Round Numbers

    The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' ...

  10. pycharm运行pytest

    pycharm运行三种方式 1.以xx.py脚本方式直接执行,当写的代码里面没用到unittest和pytest框架时,并且脚本名称不是以test_开头命名的,此时pycharm会以xx.py脚本方式 ...