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 ...
随机推荐
- spring中@value注解需要注意
首先,@value需要参数,这里参数可以是两种形式:@Value("#{configProperties['t1.msgname']}")或者@Value("${t1.m ...
- 297 - Quadtrees (UVa)
Quadtrees A quadtree is a representation format used to encode images. The fundamental idea behind t ...
- WPF - EventSetter
WPF中添加Event 1. ListBox中添加Event <ListBox x:Name="itemsControl" BorderThickness="0&q ...
- 使用javascript判断浏览器类型
之前在项目中遇到过要针对不同浏览器做不同的一些js或者css操作,后来某个朋友也突然问到这个问题,所以,整理了一下,在这里留个笔记,方便以后使用. 使用javascript判断浏览器类型: funct ...
- Ubuntu + Win7 双系统 重装win7后进入不了Ubuntu
机子上先有win7,然后装Ubuntu,装完Ubuntu后,开机进入Ub开机界面,里面有ubuntu,win7 loader(启动项),选择win7启动后就出现读盘错误. 天,我怎么能修复好这双系统启 ...
- SVN经常使用命令说明
SVN版本号:1.5 及更新版本号 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本号控制的 SVN是什么? SVN是开源的版本号控制系统. 比CVS很多其它 ...
- redis 控制调用频率
redis提供了rate limit demo 如下所示: INCR key Available since 1.0.0. Time complexity: O(1) Increments the n ...
- 通过源码安装最新版Git
下载源码 到Git的Github主页上下载最新的源码到本地,解压并进入目录. 编译安装 cd 你的git源码目录 autoconf ./configure make 第一个报错 报错内容: usr/b ...
- OD: Windows Kernel Debug
内核调试入门 内核程序运行在内核态,因此不能像对用户态应用程序那样来调试.关于内核调试方面的知识请参考<软件调试>这本书.目前内核调试主要有以下三种方法. 一是使用硬件调试器,它通过特定的 ...
- php long time(1)
好久好久没有发表新的文章了,主要是懒得在这里写,都记在记事本上,所得都是自己理解的情况下写的,如今借此闲暇记录下来,:::: ****************PHP****************** ...