XidianOJ 1172 Hiking
题目描述
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的更多相关文章
- 1172. Ship Routes
http://acm.timus.ru/problem.aspx?space=1&num=1172 水题DP 大整数直接上java 代码: import java.math.BigInte ...
- 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 ...
- hdu 2425 Hiking Trip
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...
- HDU 5360 Hiking 登山 (优先队列,排序)
题意: 有n个人可供邀请去hiking,但是他们很有个性,每个人都有个预期的人数上下限[Li,Ri],只有当前确定会去的人数在这个区间内他才肯去.一旦他答应了,无论人数怎样变更,他都不会反悔.问最多能 ...
- Mysql报错:1172 - Result consisted of more than one row
执行mysql函数时报错:1172 - Result consisted of more than one row 函数语句中select into语句中WHERE account = userNam ...
- Gym 100531H Problem H. Hiking in the Hills 二分
Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...
- 1172 Hankson 的趣味题[数论]
1172 Hankson 的趣味题 2009年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Descrip ...
- [优先队列]HDOJ5360 Hiking
题意:有n个人,每个人有两个参数$l$和$r$ 邀请他们去hiking, 当 当前已经邀请到的人数大于等于$l$,并且小于等于$r$,那么这个人就会去 问最多能邀请到几个人 并输出 依次要邀请的人的 ...
- lightOJ 1172 Krypton Number System(矩阵+DP)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1172 题意:一个n进制(2<=n<=6)的数字,满足以下条件:(1)至少包 ...
随机推荐
- Tuple方法
组元是C# 4.0引入的一个新特性,编写的时候需要基于.NET Framework 4.0或者更高版本.组元使用泛型来简化一个类的定义. public class Point { public int ...
- oracle字符函数
UPPER(char) 小写转大写 LOWER(char) 大写转小写 INITCAP(char) 首字母转换 SUBSTR(char,[m[,n]]) 截取字符串函数 从源字符串char的m开始截取 ...
- C#中的GDI+图形绘制方法
GDI+图形绘制方法 1.首先对于绘制图形,必须的先将命名空间导入:using System.Drawing.Drawing2D; 2.然后在一个事件中写入程序 首先先将Graphics这个对象实例化 ...
- codeforces194a
link:http://codeforces.com/contest/334/problem/A 很有意思的一道构造题.发现CF上经常出这种不难但是很不错的构造题. #include <iost ...
- ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java
Given two integers representing the numerator and denominator of a fraction, return the fraction in ...
- 【转】Android M(6.0) 权限爬坑之旅
原文网址:https://yanlu.me/android-m6-0-permission-chasm/ 有一篇全面介绍Android M 运行时权限文章写的非常全面:Android M 新的运行时权 ...
- js 实现ActiveXObject("Scripting.Dictionary") 功能
/* 字典 ActiveXObject("Scripting.Dictionary") 项目中用到的ActiveXObject("Scripting.Dictionary ...
- KO+bootstrap 模态窗全选绑定
HTML <div id="modalAreaID01"> <button type="button" class="btn btn ...
- FullCalendar只可以从外部拖入,内部不能互相拖动
startDrag: function(ev) { if(ev.originalEvent.initEvent){ return; } if (!this.isListening) { // star ...
- 黄聪:wkhtmtopdf--高分辨率HTML转PDF
下载:http://wkhtmltopdf.org/ 代码篇 浏览了很多实例,总找不到既能把HTML保存为PDF,同时实现流抛出的,所以自己琢磨了许久,终于实现了这样两个需求的结合体,下面来贡献一下吧 ...