题目描述

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. Block存储区域

    Block存储区域 首先,需要引入三个名词: ● _NSConcretStackBlock ● _NSConcretGlobalBlock ● _NSConcretMallocBlock 正如它们名字 ...

  2. bigworld源码分析(5)——BaseApp分析

    BaseApp负载部分,核心代码缺失...网上的源码中都找不到,暂时没办法分析其核心内容,很遗憾,继续寻找吧,等找到了,再继续自己的分析.

  3. Erlang 102 Erlang并发编程

    笔记系列 Erlang环境和顺序编程Erlang并发编程Erlang分布式编程YawsErlang/OTP 日期              变更说明 2014-11-02 A outline 2014 ...

  4. 动态添加Marquee标签,并动态赋值与属性

    前台加载js $(function(){ var publishStr="<%=publishText%>" var marqueeStr=" <mar ...

  5. bootstrap-13

    bootstrap框架中制作导航条主要通过“.nav”样式.默认的.nav样式不提供默认的导航方式,必须附加另外一个样式才会有效,比如.nav-tabs,.nav-pill之类. 导航(标签型导航): ...

  6. find查找命令的各种使用方法

    find是文件查找工具,实时查找,速度慢,精确匹配 find命令基本使用格式 find [options] [查找路径] [查找条件] [处理动作] 查找路径:默认为当前目录 查找条件:默认为查找指定 ...

  7. Deleting backup_label on restore will corrupt your database!

    The quick summary of this issue is that the backup_label file is an integral part of your database c ...

  8. 【转】编译quickfast解析库(沪深level2行情转码库)

     转自http://blog.csdn.net/hacode/article/details/7065889 编译quickfast解析库(沪深level2行情转码库) 目录(?)[-] 1 下载源代 ...

  9. angular+bootstrap+MVC--之一,入门

    这篇直奔MVVM主题,本例实现一个bootstrap的下拉框. 展示了如下技术: 1.MVVM绑定(事件绑定,值绑定,循环绑定,循环绑定中嵌套事件并回传item), 2.angul多module, 建 ...

  10. [zz]计算 协方差矩阵

    http://www.cnblogs.com/chaosimple/p/3182157.html http://blog.csdn.net/goodshot/article/details/86111 ...