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. 记录一次面试中的HTTP请求相关问题

    1.HTTP中的状态码分别代表什么 比较基础,自行百度.   2.HTTP请求,响应头部content-length用来做什么的 答:Content-Length首部告诉浏览器报文中实体主体的大小.这 ...

  2. Date和 Calendar

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  3. 每天CSS学习之box-shadow

    box-shadow是CSS3的属性,目的是给盒子添加一个或多个阴影.怎么感觉有点像光明使者使用该法术照亮敌人的阴暗面? box-shadow一共有六个属性,请看: box-shadow: h-sha ...

  4. Oauth2.0:Access Token 与 Refresh Token

    access token 是客户端访问资源服务器的令牌.拥有这个令牌代表着得到用户的授权.然而,这个授权应该是临时的,有一定有效期.这是因为,access token 在使用的过程中可能会泄露.给 a ...

  5. C/C++知识补充(2) C/C++操作符/运算符的优先级 & 结合性

    , 逗号操作符 for( i = 0, j = 0; i < 10; i++, j++ ) ... 从左到右   Precedence Operator Description Example ...

  6. 深入理解java虚拟机---java虚拟机的发展史(四)

    1.java虚拟机 A:java虚拟机有很多个版本,但是我们经常使用的是sun公司的HotSpot,可以通过以下命令获取java虚拟机版本 B:JAVA虚拟机分类: 1.Sun Class VM 2. ...

  7. jQuery $.each()常见的几种使用方法

    <code class="language-html"><!doctype html> <html> <head> <meta ...

  8. matlab中循环的使用

    转载自 https://blog.csdn.net/ssure/article/details/30329601 matlab 中的while循环只有 while statement .... end ...

  9. angular2组件通讯的几种方式

    最近刚刚接触angular2,对ng2也是一知半解,如有说得不对的地方欢迎指出,欢迎加q共同探讨学习991085978: 1.通过输入型绑定把数据从父组件传到子组件 HeroChildComponen ...

  10. SQL--数据--基本操作

    数据操作 新增数据 有两种方案方案1:给全表字段插入数据,不需要指定字段列表:要求数据的值出现的顺序必须与表中设计的字段出现的顺序一致:凡是非数值数据,都需要使用引号(建议是单引号)包裹 insert ...