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. ICSharpCode.SharpZipLib.Zip 压缩文件

    public class ZipFileHelper { List<string> urls = new List<string>(); void Director(strin ...

  2. CSS的文本属性

    CSS 文本属性可定义文本的外观. 通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本,对文本进行缩进等. ㈠缩进文本   text-indent  通过使用 text-indent 属性 ...

  3. sublime text怎么格式化PHP代码

    手动安装: 可能由于各种原因,无法使用代码安装,那可以通过以下步骤手动安装Package Control: 1.点击Preferences > Browse Packages菜单 2.进入打开的 ...

  4. 探讨MySQL的各类锁

    参考文档:http://blog.csdn.net/soonfly/article/details/70238902 锁是计算机协调多个进程或纯线程并发访问某一资源的机制.在数据库中,除了传统的计算机 ...

  5. [HG]腿部挂件 题解

    前言 暴力跑的比正解快. 以下暴力(循环展开+fread读入输出优化) #include<cstdio> #pragma GCC optimize(3, "Ofast" ...

  6. Link Script 学习

    最后更新 2019-06-27 概述 当使用 C 或者 C++ 编写代码实现某种功能时,需要将源代码进行编译以及链接.链接是将一系列目标文件(.o)以及归档文件(.a)组合起来,重新定位各个文件数据并 ...

  7. 详解vue的diff算法原理

    我的目标是写一个非常详细的关于diff的干货,所以本文有点长.也会用到大量的图片以及代码举例,目的让看这篇文章的朋友一定弄明白diff的边边角角. 先来了解几个点... 1. 当数据发生变化时,vue ...

  8. 分布式-网络通信-IO-基础(1)

    IO整体图架构  一.IO流概述 概述: IO流简单来说就是Input和Output流,IO流主要是用来处理设备之间的数据传输,Java对于数据的操作都是通过流实现,而java用于操作流的对象都在IO ...

  9. PHP 页面中实现数据的增删改查

    main页面(主页面) <table width="100%" border="1" cellpadding="0" cellspac ...

  10. Servlet基础总结

    1.Servlet概念: Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间 ...