题目描述

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. 史上最全的html标签属性用法对照表

    html标签特效代码语法使用对照说明 <!> 跑马灯 <marquee>...</marquee>普通卷动 <marquee behavior=slide&g ...

  2. Egit Patch

    Git为我们提供了Patch功能,Patch中包含了源码更改的描述,能够应用于其他Eclipse工作空间或者Git仓库.也就是说,可以将当前提交导出至其他分支或者项目中. 举个例子,项目A.B中使用了 ...

  3. 新冲刺Sprint3(第二天)

    一.Sprint介绍 更新商品图片功能已经完成,准备实现浏览商家相关信息功能和更新商品价格.商品描述功能. 二.Sprint周期 看板: 燃尽图:

  4. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  5. POJ 2481 Cows(树状数组)

                                                                      Cows Time Limit: 3000MS   Memory L ...

  6. VISIBLE、INVISIBLE、GONE的区别

    VISIBLE:设置控件可见 INVISIBLE:设置控件不可见 GONE:设置控件隐藏 而INVISIBLE和GONE的主要区别是:当控件visibility属性为INVISIBLE时,界面保留了v ...

  7. 解决IIS7该问.svc文件的错误问题

    解决IIS7.5中部署WCF时,访问.svc文件的404错误问题如果你直接在IIS 7中配置WCF,访问.svc文件时会出现404错误.解决方法,以管理员身份进入命令行模式,运行:"%win ...

  8. 【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)

    为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪. 花了好久,追踪到了这个执行过程. 进入main ...

  9. eclipse中没有R文件

    换了台电脑,把eclipse安装上去,很久没用,最近用了一下.发现R文件无法生成.试了各种方法. Project-->Clean:从其他的项目中,复制一个R.java过来:检查语法:勾选上了Pr ...

  10. DOM节点的修改

    首先,我们将最后段落赋值给变量my: var my = document.getElementById('closer'); 接下来,我们就能够轻松地通过修改对象的innerHTML值来修改段落中的文 ...