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

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
题意:给你n中给定数量的不同价值的东西,问怎么样分才能使得两堆的差最小;
解题思路:动态规划中平分东西问题有一个模板:将它所给出的n个东向西加起来sum,将sum/2当作体积,求出在sum/2下的最大值,sum-dp[sum/2];
感悟:01背包问题不能看的太简单,其衍生出来的东西太多了;
代码:
#include

#include

#include

#define maxn 255555

using namespace std;

int main()

{

   
//freopen("in.txt","r",stdin);

    int
n,m,v,f[maxn],dp[maxn];

   
while(~scanf("%d",&n),n>0)

    {

       
memset(dp,0,sizeof dp);

       
int d=0,sum=0;

       
for(int l=0;l

       
{

           
scanf("%d%d",&v,&m);

           
for(int i=0;i

           
{

               
f[d++]=v;

               
sum+=v;

           
}//将数据记录到数组,并且求出虽多的价值数

       
}

       
for(int i=0;i

           
for(int j=sum/2;j>=f[i];j--)

       
{

           
dp[j]=max(dp[j],dp[j-f[i]]+f[i]);

       
}

       
printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);

    }

    return
0;

}

Problem S的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. CSDN博客新手使用方案

    CSDN博客简易使用 在CSDN上写博客,总是遇到很多问题,虽然这些问题很简单,但是对于新手来说,缺经常遇到,因此写篇博客记载. 一.CSDN的博客如何上传图片               如果有现成 ...

  2. 西邮linux兴趣小组2014纳新免试题(五)

    [第五关] 题目 http://final5.sinaapp.com/ 关注西邮Linux微信平台,得到一个名为a的文件 分析 分析文件a 需要反汇编,拿IDA上,打开后发现key_function及 ...

  3. ThinkPHP中:RBAC权限控制的实习步骤

    使用版本ThinkPHP3.1.3 第一步,建表及数据 第二步,建关联模型 第三步,控制器使用关联模型.配置文件 第四步,模板显示数据 第一步,建表及数据 在数据库中,建立一个companysvn数据 ...

  4. 项目管理软件之争,禅道和JIRA大对比

    本文摘要: 一. 产品介绍 二. 界面设计 1. 界面颜色设计 2. 布局结构 三. 功能区别 四. 价格对比 五. 后期服务 六. 优缺点 七. 总结 说到项目管理软件,不得不提的是禅道和JIRA. ...

  5. Python数据分析流程

    一.数据分析的步骤: 1.查看数据并提出问题 2.数据清洗 3.代码编写,提取出结果数据,并分析是否有异常数据,修改代码 4.根据数据选择合适的图表进行展示 5.根据图表小组讨论交流获得最终的结果 二 ...

  6. 入坑IT十年(二)技术以外

    上一篇博客里提到:技术越来越简单,发布后不久,就看到<技术并不是越来越简单>,这显然是打擂台来了. 技术究竟是不是越来越简单?其实这个问题,要看你究竟是以什么角度来思考这个问题.我们可以举 ...

  7. 数据的分类-JavaScript数据类型

    JavaScript数据类型 1.数据类型是什么? 我们接触的绝大多数程序语言来说,把数据都进行了分类,包括数字.字符.逻辑真假:int,long,string,boolean....等等:我们都知道 ...

  8. PHP计算上个月的开始时间和结束时间戳

    $m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); $t = date('t',strtotime($m)); //上个月共多少天 $ ...

  9. 在linux上安装rz、sz包

    在SecureCRT这样的ssh登录软件里, 通过在Linux界面里输入rz/sz命令来上传/下载文件. 对于RHEL5, rz/sz默认没有安装所以需要手工安装.sz: 将选定的文件发送(send) ...

  10. webpack 的使用1

    进入指定文件夹  npm init 安装 npm install webapck --save-dev 根目录下新建hello.js 将文件打包到指定文件  Asset :打包成的文件名称 Chunk ...