Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51519    Accepted Submission(s): 17609

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
 
Author
lcy
 

代码:

 #include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int val[N],dp[N];
int main(){
int n,a,b,len,sum;
while(~scanf("%d",&n),n>){
memset(dp,,sizeof(dp));
memset(val,,sizeof(val));
len=;sum=;
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
while(b--){
val[len++]=a;
sum+=a;
}
}
for(int i=;i<len;i++){
for(int j=sum/;j>=val[i];j--){
dp[j]=max(dp[j],dp[j-val[i]]+val[i]);
}
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}

HDU 1171.Big Event in HDU-动态规划0-1背包的更多相关文章

  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(01背包)

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

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

  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

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

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

    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(母函数)

    链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...

  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 dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

  10. HDU 1171 Big Event in HDU 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory ...

随机推荐

  1. FileStream流媒体

    class Program { static void Main(string[] args) { string source = @"mana.mp4"; string targ ...

  2. DOS程序员手册(十三)

    744页 在DPMI 1.0下,系统会修改并重新装载所有含选择符的段寄存器,并且将所有 含有要释放的选择符的寄存器清空为0. 客户程序绝不能修改或释放该功能分配的任何描述符.Int 31h.功能010 ...

  3. COMMIT和ROLLBACK的用法

    从功能上划分,SQL语言可以分为DDL,DML和DCL三大类. 1.DDL(Data Definition Language)  数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 : C ...

  4. pytorch:EDSR 生成训练数据的方法

    Pytorch:EDSR 生成训练数据的方法 引言 Winter is coming 正文 pytorch提供的DataLoader 是用来包装你的数据的工具. 所以你要将自己的 (numpy arr ...

  5. SQL视频总结

    SQL是英文Structured Query Language的缩写,意思为结构化查询语言. SQL语言的主要功能就是同各种数据库建立联系,进行沟通.SQL被作为关系型数据库管理系统的标准语言. SQ ...

  6. C#如何在keydown事件里判断按下的是左shift还是右shift

    public partial class Form1 : Form { [System.Runtime.InteropServices.DllImport("user32.dll" ...

  7. Codeforces755D PolandBall and Polygan

    题目戳这里 我们只需要计算每增加一条线后穿过了几条已有的线即可.为了方便,我们令\(K \le N/2\),并且给每条线一个方向,即\(x\)到\((x+K) \; mod \; N\).然后我们假设 ...

  8. flex弹性布局的基本介绍

    最近开始做元素排列比较复杂的项目,同时需要各种型号手机的适配,我发现以前所掌握的盒子模型.display.position.float等已经不能满足我的需求了, 于是开始着重学习flex弹性布局并运用 ...

  9. java 复习整理(一 java简介和基础语法)

    现在公司用的是封装太多东西的平台开发,觉着之前学的东西很多都忘了,所以想好好总结回顾一下.之前总是想学很多编程语言像python.s6.node.react,但现在越来越体会到编程语言只是一个开发的工 ...

  10. 第二届360杯全国大学生信息安全技术大赛部分解题思路(WEB安全)

    第一题如下: 用burpsuit设置好代理后,点击发送验证码,可以看到如下: 然后go之后可以看到如下的验证码: 提交验证码后即可获得key 第二题如下: 通过/data/mysql_error_tr ...