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 ...
随机推荐
- Java for LeetCode 214 Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- Divide and conquer:4 Values whose Sum is 0(POJ 2785)
找四个数的和为0 题目大意:给定四个集合,要你每个集合选4个数字,组成和为0 这题是3977的简单版,只要和是0就可以了 #include <iostream> #include < ...
- RSA 加解密转换
由于项目的原因,原来的项目使用.net 进行开发,现在需要转成java, 所以原来的加解密就成了一个棘手的问题.由于数据使用RSA签名加密,又因为.net 和 Java 加解密算法上的差异,并不能使用 ...
- uva 1584.Circular Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- tomcat bin 中startup.sh中的环境变量配置
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 JRE_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64/jre P ...
- struts2环境配置
struts2环境配置 struts2框架,大多数框架都在使用.由于工作需要,开始做Java项目.先学个struts2. 一.下载struts2 有好多版本,我下载的是struts-2.2.1.1. ...
- sqlserver 动态行转列
DECLARE @SQL VARCHAR(8000)SET @SQL = 'select overcode 'SELECT @SQL = @SQL + ' , max(case header when ...
- java调用cmd命令删除文件夹及其所有内容
/** * *删除D盘下面test目录,感觉以前用io流遍历删除好慢! * **/ public static void main(String[] args) { Runtime run = Run ...
- 细谈WEB标准
最近有些朋友很是疑惑web标准是什么,我在这里先做一个总结,有更好的见解的可以私信给我! 首先切入正题之前先谈一下什么叫DOCTYPE,DOCTYPE是document type(文档类型)的简写,主 ...
- 使用 ODBC .NET 提供程序和 Visual C# .NET 执行 SQL 参数化存储过程
http://support2.microsoft.com/kb/310130/zh-cn 此分步指导文章描述如何使用 ODBC .NET 托管提供程序和 Visual C# .Net 调用参数化 S ...