博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu-1171Big Event in HDU(dp的应用)
阅读量:4049 次
发布时间:2019-05-25

本文共 2012 字,大约阅读时间需要 6 分钟。

Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34864    Accepted Submission(s): 12087
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
 
Recommend

We have carefully selected several similar problems for you:  2159 2844 1087 2191 1176 

思路是相当于把总和的一半作为背包的容量 01背包模型 b[sum/2]为一个值  sum-b[sum/2]为另一个值

#include
#include
#include
#include
using namespace std;int a[5005];int b[255555];int main(){ int n,m,i,k,p,q,sum; while(scanf("%d",&n)&&n>0) { k=0; sum=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0;i
=a[i];j--) { b[j]=max(b[j],b[j-a[i]]+a[i]); } } printf("%d %d\n",sum-b[sum/2],b[sum/2]); } return 0;}

转载地址:http://cxfci.baihongyu.com/

你可能感兴趣的文章
从mysql中 导出/导入表及数据
查看>>
HQL语句大全(转)
查看>>
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
关于进制转换的具体实现代码
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>