uva 10032 Problem F: Tug of War
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=973
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; int w[];
int n;
ll dp[]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int sum=;
for(int i=; i<n; i++)
{
scanf("%d",&w[i]);
sum+=w[i];
}
memset(dp,,sizeof(dp));
dp[]=;
for(int i=; i<n; i++)
{
for(int j=sum; j>=w[i]; j--)
{
dp[j] |= dp[j-w[i]]<<;
}
}
int ans1=,ans2=0x3f3f3f3f;
for(int i=; i<=sum; i++)
{
for(int j=; j<=(n+)/; j++)
{
if(dp[i]&(1ll<<j) && abs(*j-n)<=)
{
if(abs(sum-*i)<ans2-ans1)
{
ans2=max(sum-i,i);
ans1=min(sum-i,i);
}
}
}
}
printf("%d %d\n",ans1,ans2);
if(t) printf("\n");
}
return ;
}
uva 10032 Problem F: Tug of War的更多相关文章
- uva 11400 Problem F Lighting System Design
紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...
- UVA - 10032 Tug of War (二进制标记+01背包)
Description Problem F: Tug of War A tug of war is to be arranged at the local office picnic. For the ...
- HDU-2576 Tug of War
http://poj.org/problem?id=2576 二维数组01背包的变形. Tug of War Time Limit: 3000MS Memory Limit: 65536K Tot ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
随机推荐
- Flask 安装 Ubuntu 14.04
学习文档: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world 中文版学习文档 开源中国版: ...
- 【深入了解cocos2d-x 3.x】定时器(scheduler)的使用和原理探究(3)
上篇文章分析到了定时器的定义.这篇的重点就是定时器是怎样执行起来的. 1.从main中寻找定时器的回调 讲定时器的执行,就不得不触及到cocos2dx的main函数了,由于定时器是主线程上执行的.并非 ...
- cocos2d-x精灵移动的方法
1.飞机发射子弹型 想要实现子弹的的飞行效果,又不想在每帧Update里计算位置,最好的方法调用CCMoveTo 例在发射子弹的时机,能够ccTouchBegan时: CCMoveTo* move = ...
- Lucene和jackson冲突
今天在使用lucene的时候,想直接在Controller中返回json对象,于是在Spring中配置了JackSon的converter: <bean id="jacksonMess ...
- Spring-----1、Spring一个简短的引论
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- C++之static
一.静态全局变量和非静态全局变量 1. 隐藏作用 比较非静态全局变量和静态(static)全局变量: 对于多个文件的代码,非静态全局变量和函数都是全局可见的.举例如下: a.c中: #include& ...
- MySQL创建新用户、增加账户的2种方法及使用实例
可以用两种方式创建MySQL账户:1.使用GRANT语句2.直接操作MySQL授权表最好的方法是使用GRANT语句,因为这样更精确,错误少.创建超级用户: mysql> GRANT ALL PR ...
- Android Studio错误
晚上一直在折腾android studio这个东西,弄的蛋疼.. 之前是有用的,然后今天闲的没事干,更新了下,反正弄出了一大堆的错误.. 错误:failed to find Build Tools r ...
- bash:ifconfig command not found for contos7.0
CentOS7刚发布,我忍不住把DELL T410从CentOS6升级到CentOS7.好不容易等安装结束后,立即配置网络,然后在yum源上安装环境.可是执行ifconfig的时候系统提示让我傻了眼: ...
- 设置Cacti图形标题能显示中文
1.查看系统是否带有中文字体包 # ls /usr/share/fonts/chinese 如没有则安装 # yum -y install fonts-chinese 2.设置cacti使用的rr ...