题目描述

BlacKin and GKCY are going hiking together.
Besides their personal items, there are some items they share together.
They decided to devide those shared items into two parts.
So each of them has to carry their own items and a part of shared items.
To make it fair, they hope the weight difference between those two parts can be as small as possible.
Now they want to know how small it can be.

输入

Multiple test cases, please read until EOF
For each test case:
First line a single integer n (1 <= n <= 200), number of shared items.
Second line n integers, Wi (1 <= Wi <= 200), weight of each item.

输出

For each test case:
One line a single integer, the smallest difference between two part.

--正文

又是宝藏分配。。。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; int f[];
int cost[];
int w,sum,n;
int main(){
while (scanf("%d",&n) != EOF){
int i,j;
sum = ;
for (i=;i<=n;i++){
scanf("%d",&cost[i]);
sum += cost[i];
}
w = sum / ;
memset(f,,sizeof(f));
for (i=;i<=n;i++){
for (j=w;j>=cost[i];j--){
f[j] = max(f[j],f[j-cost[i]] + cost[i]);
}
}
int res = sum - *f[w]; if (res < ) res = -res;
printf("%d\n",res);
}
}

XidianOJ 1172 Hiking的更多相关文章

  1. 1172. Ship Routes

    http://acm.timus.ru/problem.aspx?space=1&num=1172 水题DP   大整数直接上java 代码: import java.math.BigInte ...

  2. Hiking 分类: 比赛 HDU 函数 2015-08-09 21:24 3人阅读 评论(0) 收藏

    Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  3. hdu 2425 Hiking Trip

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...

  4. HDU 5360 Hiking 登山 (优先队列,排序)

    题意: 有n个人可供邀请去hiking,但是他们很有个性,每个人都有个预期的人数上下限[Li,Ri],只有当前确定会去的人数在这个区间内他才肯去.一旦他答应了,无论人数怎样变更,他都不会反悔.问最多能 ...

  5. Mysql报错:1172 - Result consisted of more than one row

    执行mysql函数时报错:1172 - Result consisted of more than one row 函数语句中select into语句中WHERE account = userNam ...

  6. Gym 100531H Problem H. Hiking in the Hills 二分

    Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...

  7. 1172 Hankson 的趣味题[数论]

    1172 Hankson 的趣味题 2009年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Descrip ...

  8. [优先队列]HDOJ5360 Hiking

    题意:有n个人,每个人有两个参数$l$和$r$ 邀请他们去hiking, 当  当前已经邀请到的人数大于等于$l$,并且小于等于$r$,那么这个人就会去 问最多能邀请到几个人 并输出 依次要邀请的人的 ...

  9. lightOJ 1172 Krypton Number System(矩阵+DP)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1172 题意:一个n进制(2<=n<=6)的数字,满足以下条件:(1)至少包 ...

随机推荐

  1. magento中如何实现产品图片放大效果

    Magento列表页用jQuery实现产品图片放大效果今天看到个网站,鼠标移到列表页的产品图片上,旁边会弹出一个大图,感觉不错,就自己在Magento里写了个.先看看效果 这个效果比较好实现,打开li ...

  2. oc实例变量初始化方法

    1 使用实例setter方法 默认初始化方法 + setName:xxx setAge:xxx 2 使用实例功能类方法,默认初始化方法 + setName:xxx age:xxx3 使用实例初始化方法 ...

  3. XML实体注入漏洞

    XML实体注入漏洞 测试代码1: 新建xmlget.php,复制下面代码 <?php $xml=$_GET['xml']; $data = simplexml_load_string($xml) ...

  4. 转-利用Oracle审计功能来监测试环境的变化

    http://blog.csdn.net/luowangjun/article/details/5627102利用Oracle审计功能来监测试环境的变化 做过测试的人都应该会碰到这样的情况:测试发现的 ...

  5. Angular2.0-组件

    截止到目前为止,Angular2.0完成了其alpha-32版本的开发,新的版本还在迭代开发当中,这其中有个问题,就是每个版本相比于以前的版本都会有一些改动,包括API方面的修改,这会导致很多基于以前 ...

  6. CSS 分组

    选择器分组 假设希望 h2 元素和段落都有灰色.为达到这个目的,最容易的做法是使用以下声明: h2, p {color:gray;} 将 h2 和 p 选择器放在规则左边,然后用逗号分隔,就定义了一个 ...

  7. ASP.NET MVC Web API 学习笔记---第一个Web API程序

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html GetListAll /api/Contact GetListBySex ...

  8. 严格模式use strict

    严格模式主要有以下限制: 变量必须声明后再使用函数的参数不能有同名属性,否则报错不能使用with语句不能对只读属性赋值,否则报错不能使用前缀0表示八进制数,否则报错不能删除不可删除的属性,否则报错不能 ...

  9. PHP使用mysqldump备份数据库(以及还原)

    导出数据实例如下: <?php $mdb_host = $g_c["db"][0]["managertool"]["host"]; / ...

  10. RPC远程过程调用协议

    最近学习Hadoop.Hbase.Spark及Storm原理,经常会出现RPC这样的传输术语,为了更好地理解,将知识点详细的整理下吧~ RPC-----它是一种通过网络从远程计算机程序上请求服务,而不 ...