Big Event in HDU

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

 

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


-

Sample Output

 

题目大意与分析

给出一堆东西的重量和个数,要尽可能的将物品分成重量接近的两堆A和B,且A的重量不小于B

求以sum/2为容量的背包即可,求出来的值就是B sum减去B就是A

代码

#include <bits/stdc++.h>
using namespace std; int val[];
int dp[]; int main()
{
int n,i,j,a,b,l,sum;
while(~scanf("%d",&n),n>)
{
memset(val,,sizeof(val));
memset(dp,,sizeof(dp));
l = ;
sum = ;
for(i = ;i<n;i++)
{
scanf("%d%d",&a,&b);
while(b--)
{
val[l++] = a;
sum+=a;
}
}
for(i = ;i<l;i++)
{
for(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 (动态规划、01背包)的更多相关文章

  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背包/求两堆数分别求和以后的差最小】

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

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

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

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

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

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

  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. HDU 1171 Big Event in HDU【01背包】

    题意:给出n个物品的价值和数目,将这一堆物品分给A,B,问怎样分使得两者的价值最接近,且A的要多于B 第一次做的时候,没有思路---@_@ 因为需要A,B两者最后的价值尽可能接近,那么就可以将背包的容 ...

  8. HDU 1171 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 dp背包

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

随机推荐

  1. JavaScript基础——JavaScript入门(笔记)

    JavaScript入门(笔记) JavaScript是一种轻量级.解释型的Web开发语言,该语言系统不是很庞杂,简单易学.由于所有现代浏览器都已嵌入JavaScript引擎,JavaScript源代 ...

  2. win10 1903 更改文字大小

    标题栏 - 菜单 - 消息框 - 调色板标题11- 图标 - 工具提示 - Caption 标题 的 宽/高 - ; 14的宽高 - 菜单 的 宽/高 - ; 的宽高 -; 设置 注册表 HKEY_C ...

  3. 任务Task、先后任务

    Task类似后台线程. using System; using System.Threading; using System.Threading.Tasks;//引用命名空间 namespace Co ...

  4. jquery pageY属性 语法

    jquery pageY属性 语法 作用:pageY() 属性是鼠标指针的位置,相对于文档的上边缘.直线模组 语法:event.page 参数: 参数 描述 event     必需.规定要使用的事件 ...

  5. 总结JavaScript中浏览器的兼容问题

    浅析JavaScript中浏览器的兼容问题 浏览器兼容性问题是在实际开发中容易忽略而又最重要的一部分.我们在讲老版本浏览器兼容问题之前,首先要了解什么是能力检测,它是来检测浏览器有没有这种能力,即判断 ...

  6. codevs 1405 牛的旅行x

    牛的旅行 [问题描述] 农民John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧场不连通.现在,John想在农场里添加一条路径 ...

  7. perl基础-2

    函数参数 perl 函数参数为$$,$$$,$@ Perl 可以通过函数元型在编译期进行有限的参数类型检验. 如果你声明 sub mypush (+@)那么 mypush() 对参数的处理就同内置的 ...

  8. Anaconda cheat sheet

    1 anaconda prompt 闪退的情况 在cmd中进入C:\ProgramData\Anaconda3\Scripts然后可以使用各种conda命令 2 anaconda 换源 # 方法参考 ...

  9. 关于MYSQL日期 字符串 时间戳互转

    时间转字符串: select date_format(now(), '%Y-%m-%d'); #结果:2016-01-05 时间转时间戳: select unix_timestamp(now()); ...

  10. RF相关命令

    结果输出 RF通过命令执行用例及自定义报告与日志的位置 1.执行整个项目下的所有用例: pybot 项目路径.例如: pybot D:\robot PS:robot项目里面所有用例 2.执行某个sui ...