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. openGPS.cn - 高精度IP定位原理,定位误差说明

    [ip定位历史] 关于IP定位,最早是通过运营商实现,每个运营商申请到的ip段,在某个范围内使用. 因此早期只能是国家为单位的基础数据. 对于比较大的国家,就进一步划分,比如,中国某通讯公司(不打广告 ...

  2. 【重点突破】——Canvas技术绘制随机改变的验证码

    一.引言 本文主要是我在学习Canvas技术绘图时的一个小练习,绘制随机改变的验证码图片,虽然真正的项目里不这么做,但这个练习是一个掌握Canvas技术很好的综合练习.(真正的项目中验证码图片使用服务 ...

  3. Muddy Fields

     Muddy Fields Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  4. 无向图广度优先遍历及其matlab实现

    广度优先遍历(breadth-first traverse,bfts),称作广度优先搜索(breath first search)是连通图的一种遍历策略.之所以称作广度优先遍历是因为他的思想是从一个顶 ...

  5. fitnesse - Variables and Symbols

    fitnesse - Variables and Symbols 2017-09-30 目录 1 Variables(静态变量)  1.1 定义及使用  1.2 Variable作用域    1.2. ...

  6. 一脸懵逼学习基于CentOs的Hadoop集群安装与配置

    1:Hadoop分布式计算平台是由Apache软件基金会开发的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS)和MapReduce(Google MapReduce的开源实现)为核心的 ...

  7. java 虚拟机与并发处理几个问题简要(一)

    一.   处理任务时,应该将代码分成不同的部分,每一部分由一个线程进行,但是会因为任务负载不平衡导致有闲有忙.最好是应分成不同的部分,分配不同的线程,尽量让处理器不停的处理,不要闲下来.如何分配线程数 ...

  8. JavaScript实现模糊推荐的input框(类似百度搜索框)

    如何用JS实现一个类似百度搜索框的输入框呢,再填充完失去焦点时,自动填充配置项,最终效果如下图: 实现很简单,但是易用性会上升一大截,需要用到的有jquery-ui的autocomplete,jque ...

  9. Python 并发编程(一)之线程

    常用用法 t.is_alive() Python中线程会在一个单独的系统级别线程中执行(比如一个POSIX线程或者一个Windows线程)这些线程将由操作系统来全权管理.线程一旦启动,将独立执行直到目 ...

  10. Python和SQL Server 2017的强大功能

    Python和SQL Server 2017的强大功能 摘要: 源:https://www.red-gate.com/simple-talk/sql/sql-development/power-pyt ...