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的更多相关文章

  1. uva 11400 Problem F Lighting System Design

    紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...

  2. 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 ...

  3. HDU-2576 Tug of War

    http://poj.org/problem?id=2576 二维数组01背包的变形. Tug of War Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  4. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  5. 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 ...

  6. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  7. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  8. 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 ...

  9. Problem F: Exponentiation

    Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...

随机推荐

  1. E - Minimum Cost - POJ 2516(最小费)

    题目大意:N个客户,M个供货商,K种商品,现在知道每个客户对每种商品的需求量,也知道每个供货商每种商品的持有量,和供货商把一种商品运送到每个客户的单位花费.现在想知道如果能满足所有客户的最小花费是多少 ...

  2. linux下ssh使用和配置

    常用格式:ssh [-l login_name] [-p port] [user@]hostname 更详细的可以用ssh -h查看. 举例 不指定用户: ssh 192.168.0.11 指定用户: ...

  3. android的intent打开系统程序

    打开设置主界面 Intent intent = new Intent(Android.provider.Settings.ACTION_SETTINGS); //系统设置 startActivityF ...

  4. cocos日记

    n/2/2015 ADT       E:\All Setup\eclipse_past\Eclipse_plugins_ADT 15/2/2015 配置cocos win32 开发环境 链接:htt ...

  5. 在ios中解析json数据

    刚刚下午那会 弄了个 解析 xml  demo的小例子,本想着json也挺复杂 弄还是 不弄,但是简单的看了下 发现挺简单 考虑了很久,还是写上来吧,毕竟json用得太多了,而且算是自己的积累吧,毕竟 ...

  6. [置顶] ios 水果连连看游戏源码

    原创文章,转载请注明出处:http://blog.csdn.net/donny_zhang/article/details/9251917 demo功能:水果连连看游戏源码.iphone6.1 测试通 ...

  7. SKPhysicsJointSpring类

    继承自 NSObject 符合 NSCoding(SKPhysicsJoint)NSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit. ...

  8. [Falcor] Retrieving Multiple Values

    In addition to being able to retrieve a path from a Falcor Model, you can also retrieve multiple Pat ...

  9. 全球最流行的66款App的共同规律

    根据苹果AppStore.Google Play.App Annie.亚马逊 AppStore及Windows Phone 应用商店历年的公开数据统计,以下66个非游戏类应用正在全球范围内流行,持续时 ...

  10. Annotation注解

    概述 Annotation是JDK 5.0以后提供对元数据的支持,可以在编译.加载和运行时被读取,并执行相应的处理.所谓Annotation就是提供了一种为程序元素设置元数据的方法,可用于修饰包.类. ...