Big Event in HDU

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

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

题意:航电要分校区,要把设备尽可能的等分,给出不同设备的价值和数量。尽可能的等分,其实可以转化为一个最大价值是所有设备总价一半的背包里面最大可以放的物品价值总和,这样算出来的是较小的那一组,或者是和另一组价值相等,另一组只要所有设备总价值减去这一组就是了。最后的输入结束有点坑,测试数据里面不一定是-1.。。。。。。

 #include<bits/stdc++.h>
using namespace std;
int dp[],v[];
int main() {
int n;
while(~scanf("%d",&n)&&n>)
{
memset(dp,,sizeof(dp));
memset(v,,sizeof(v));
int sum=,l=;
for(int i=;i<n;i++)
{
int a,b;
scanf("%d %d",&a,&b);
while(b--)
{
v[l++]=a;//价值
sum+=a;
}
} for(int i=;i<l;i++)
{
for(int j=sum/;j>=v[i];j--)//因为要分成两组价值相近的,所以背包的总价值
{ //直接设成全部物品总价值的一半,因为这里时从一半的时候
dp[j]=max(dp[j],dp[j-v[i]]+v[i]);//向下递减的,所以最后dp[sum/2]里面的
} //存的就是较小的那一组
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}

hdu1171Big Event in HDU(01背包)的更多相关文章

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

  2. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  3. 1171 Big Event in HDU 01背包

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...

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

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

  5. Big Event in HDU(01背包)

    /* 题意: 输入一个数n代表有n种物品, 接下来输入物品的价值和物品的个数: 然后将这些物品分成A B 两份,使A B的价值尽可能相等也就是尽量分的公平一些,如果无法使A B相等,那么就使A多一些: ...

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

    题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++ ...

  7. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

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

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

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

随机推荐

  1. 微信公众号支付IOS系统能够唤起,安卓系统不能唤起的问题解决

    前言 之前系统内做过要给微信支付程序,只不过鉴于业务应用场景,大部分都是使用业务内的金币兑换产品,没有实际用到支付功能.后来运营小哥哥说他的手机不能唤起支付.于是乎我查询了一下资料,发现了这么个问题. ...

  2. table中实现数据上移下移效果

    html 由于vue+Element项目中的table,没有开放的上移下移的api,但是能对数据操作,故思路为数组中的一条数据,再重新添加一条数据,办法有点笨,但是好歹也是实现了,望有好的办法的,请留 ...

  3. js去除空格(trim方法)

    /** * 去空格 */ String.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, ""); ...

  4. 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)

    洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...

  5. 五、MapReduce 发布服务

    是一个并行计算框架(计算的数据源比较广泛-HDFS.RDBMS.NoSQL),Hadoop的 MR模块充分利用了HDFS中所有数据节点(datanode)所在机器的内存.CUP以及少量磁盘完成对大数据 ...

  6. oracle使用DBMS_RANDOM包生成随机数据

    (一)DBMS_RANDOM包信息 DBMS_RANDOM包包含3个存储过程,4个函数,1个类型,一共8个模块,如下. SQL> desc dbms_random Element Type -- ...

  7. JS中new运算符的实现原理

    当我们用new运算符new一个构造函数产生一个实例时,比如说: var obj = new Func 时,其背后的步骤是这样的: 1:创建一个继承自 Func.prototype 的新对象:2:执行构 ...

  8. 缓存反向代理-Varnish

    简介 Varnish是一款高性能.开源的缓存反向代理服务器.它从客户端接受请求,并尝试从缓存中响应请求,如果无法从缓存中提供响应,Varnish 向后端服务器发起请求,获取响应,将响应存储在缓存中,然 ...

  9. 登录验证码的生成Java代码

    package example7; import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;import java. ...

  10. 一、Vue项目构建

    Attention:以下内容为Mac机上运行,windows可能有所偏差- Step1 打开终端,键入npm install -g vue-cli,使用vue-cli脚手架搭建vue项目能省很多事儿- ...