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. HPROF学习

    抓取HPROF log 1. GUI 可以通过 adt-bundle-windows-x86_64-20140702\sdk\tools\monitor.bat来抓取. 打开软件,选中相应的包,比如“ ...

  2. 最长回文子串(百度笔试题和hdu 3068)

    版权所有.所有权利保留. 欢迎转载,转载时请注明出处: http://blog.csdn.net/xiaofei_it/article/details/17123559 求一个字符串的最长回文子串.注 ...

  3. 持久化API(JPA)系列(三)实体Bean的开发技术-建立与数据库的连接

    在EJB 2.x中.EJB有3种类型的Bean.各自是会话Bean(Session Bean).消息驱动Bean(Message-Driven Bean)和实体Bean(Entity Bean). 随 ...

  4. Lucene和jackson冲突

    今天在使用lucene的时候,想直接在Controller中返回json对象,于是在Spring中配置了JackSon的converter: <bean id="jacksonMess ...

  5. POJ 2044 Weather Forecast

    意甲冠军:有一2*2云,而一个4*4范围.在当天密布区必须有雨.有云4招式种类 .期间希望不要下雨,并且一个地方不能有连续7天没下雨. 思路:首先解决一个地方不能有连续7天没下雨的情况,要让地图上的全 ...

  6. 图片样式 scaleType 属性

    ImageView的属性android:scaleType,即ImageView.setScaleType(ImageView.ScaleType),不同值的意义区别:

  7. css元素居中

    水平居中 若为行内元素,对其父元素用text-align:center即可: 若为块元素(无浮动),则一般有两种方法可实现对其的水平居中,一为margin:0 auto;二为通过css计算函数calc ...

  8. Asp.Net WebAPI 中Cookie 获取操作方式

    1. /// <summary> /// 获取上下文中的cookie /// </summary> /// <returns></returns> [H ...

  9. 第二章 控件架构与自定义控件详解 + ListView使用技巧 + Scroll分析

    1.Android控件架构下图是UI界面架构图,每个Activity都有一个Window对象,通常是由PhoneWindow类来实现的.PhoneWindow将DecorView作为整个应用窗口的根V ...

  10. Swift2.0异常处理

    // 在抛出异常之前,我们需要在函数或方法的返回箭头 -> 前使用 throws 来标明将会抛出异常 func myMethodRetrunString() throws -> Strin ...