Big Event in HDU
Description
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
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40 好久不刷题了,看到这个题一点思路也没有。后来想了一下,其实不难。把一组数,分解为和尽量相等的2组数。
看作01背包问题,背包容量为sum/2,求怎么组合可以最大可能的接近sum/2.
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int val[*+];
int dp[];
int max(int a,int b)
{
if(a>=b) return a;
else return b;
}
int main()
{ int n;
while(~scanf("%d",&n)&&n>)
{
memset(dp,,sizeof(dp));
int sum=;
int num=;
for(int i=;i<n;i++)
{
int tmp1,tmp2;
scanf("%d%d",&tmp1,&tmp2);
while(tmp2>)
{
val[num++]=tmp1;
sum+=tmp1;
tmp2--;
}
}
for(int i=;i<num;i++)
{
for(int j=sum/;j>=val[i];j--)
{
dp[j]=max(dp[j-val[i]]+val[i],dp[j]);
}
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}
Big Event in HDU的更多相关文章
- HDU-1171 Big Event in HDU
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- Big Event in HDU(HDU1171)可用背包和母函数求解
Big Event in HDU HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1 结果是:20 10.才最均匀! 三 ...
- 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 ...
- Big Event in HDU[HDU1171]
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1171——Big Event in HDU(母函数)
Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...
- Big Event in HDU(HDU 1171 多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu1171 Big Event in HDU 01-背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...
- HDU1171-Big Event in HDU
描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...
随机推荐
- linux 配置tomcat运行远程监控(JMX)
在实际使用中,我们经常要监控tomcat的运行性能.需要配置相应的参数提供远程连接来监控tomcat服务器的性能.本文详细介绍如何一步一步的配置tomcat相应参数.允许远程连接监控. 工具/原料 v ...
- 【python】datetime获取日期,前一天日期
1.获取字符串型当前日期 2016-10-09格式 import datetime today = datetime.date.today() #datetime.date类型当前日期 str_tod ...
- 【python】词法语法解析模块ply
官方手册:http://www.dabeaz.com/ply/ply.html 以下例子都来自官方手册: 以四则运算为例: x = 3 + 42 * (s - t) 词法分析: 需要将其分解为: 'x ...
- 如何获得images.xcassets 中图片的路径?
UIImage加载图片的方式以及Images.xcassets对于加载方法的影响 重点: Images.xcassets中的图片资源只能通过imageNamed:方法加载,通过NSBundle的pat ...
- 【转】字符集和字符编码(Charset & Encoding)
相信大家一定碰到过,打开某个网页,却显示一堆像乱码,如"бЇЯАзЪСЯ"."�????????"?还记得HTTP中的Accept-Charset.Accept ...
- NYOJ之喷水装置(一)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsUAAAJvCAIAAAAcLjvHAAAgAElEQVR4nO3drXLjzNaG4e8kzH0gof
- 给UILabel设置不同的字体和颜色
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAt ...
- Avalon学习
1.认识AvalonAvalon是一个简单易用的迷你的MVVM框架,作者是博客园的司徒正美,去哪儿.搜狐等等都用这个框架.没有任何依赖,兼容性非常好,支持IE6,不到5000行,压缩后不到50KB.官 ...
- Delphi编程建议遵守的规范1---缩进、各种语句的用法
在编程时候,尤其是在一个大的团队里面,遵守统一的编程规范是极其重要的.为所有的开发人员制定一个源代码书写标准,以及程序和文件的命名标准,使他们在编程时有一致的格式,这样,每个编程人员编写的代码能够被其 ...
- [LeetCode] Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...