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 ...
随机推荐
- hyperVisors
容器有效地将由单个操作系统管理的资源划分到孤立的组中,以更好地在孤立的组之间平衡有冲突的资源使用需求 期望继续进军中国市场 就像IBM公司,惠普公司和戴尔公司在中国服务器市场的霸主地位一样,Inspu ...
- 西装定制平台Indochino获$1350万B轮融资 - 国际B2C - 亿邦动力网
西装定制平台Indochino获$1350万B轮融资 - 国际B2C - 亿邦动力网 西装定制平台Indochino获$1350万B轮融资 作者: 韦龑来源: i黑马网2013-03-29 11:05 ...
- OBJ-C
1.直接赋值 NSString *name = @"Starain"; 2.用已经存在的字符串进行初始化 NSString *name2 = [NSString stringWit ...
- EasyUEFI
---------------------------------http://www.easyuefi.com/downloads/EasyUEFI_Setup.exe--------------- ...
- jsp页面中定时的方法
$(function(){ totaladd(); //定时时触发的函数 setInterval(totaladd,3000);//设置定时1000=1秒 }); function totaladd( ...
- hdu 2190
//hdu2190 水题 题意是给一个n*3的教室,用1*1,2*2的砖去铺满,有多少种铺法,一开始没发现这个规律,想了一下,应该是递归. #include <iostream> usi ...
- JQuery简单实现图片轮播效果
很多页面都需要用到界面轮播,但是用原生js相对来说比较复杂,用jQuery实现效果比较迅速,写个简单的demo 1.首先在HTML页面要放置轮播图案位置插入div,这里写了轮播图片数量为3张,所以定义 ...
- 你确定你是一个合格的.Net开发人员吗?
做.net开发已有近5年时间,自认掌握的知识比较全面.最近部门需要招人,今天抽空在网上看了一下,发现我了解的还是不够多啊.下面是我大致的罗列了一下作为一名.Net开发人员所需要掌握的只是.看看你是不是 ...
- (转)第三方登录(QQ登录)开发流程详解
近排由于工作的繁忙,已经一个星期没写博文做分享了,接下来我对网站接入第三方登录----QQ登录的实现逻辑做一个详细的讲解. 对于整个流程的详细文档可以到QQ互联官网(http://wiki.conne ...
- css空格和去浮动的应用
今天做了项目用到css,请教前端解决,第一个是记得css空格之间的关系是隶属关系,但是在元素中却是并列关系,如<div class="right_side_item_moban gra ...