link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=503

分成2半,并且两半的差距最小,背包的体积变成V/2

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int V, c[], w[], f[], n;
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int t; cin>>t;
while (t--)
{
cin>>n; int sum=;
for (int i = ; i < n; ++i)
{
cin>>c[i]; sum+=c[i];
}
V=sum/;
memset(f, , sizeof(f));
for (int i = ; i < n; ++i)
{
for (int v = V; v>=c[i]; --v)
{
f[v] = max(f[v], f[v-c[i]]+c[i]);
}
}
cout<<fabs(f[V]-(sum-f[V]))<<endl;
}
return ;
}

这题就用codeblocks写的,写的好纠结,不习惯,囧

uva562 Dividing coins 01背包的更多相关文章

  1. UVA 562 Dividing coins --01背包的变形

    01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostre ...

  2. UVA 562 Dividing coins (01背包)

    //平分硬币问题 //对sum/2进行01背包,sum-2*dp[sum/2] #include <iostream> #include <cstring> #include ...

  3. UVA 562 Dividing coins(dp + 01背包)

    Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...

  4. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  5. uva 562 Dividing coins(01背包)

      Dividing coins  It's commonly known that the Dutch have invented copper-wire. Two Dutch men were f ...

  6. UVA 562 Dividing coins (01背包)

    题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum,   A,B其中必有一人获得的钱小于等于sum/2 ...

  7. UVA 562 Dividing coins 分硬币(01背包,简单变形)

    题意:一袋硬币两人分,要么公平分,要么不公平,如果能公平分,输出0,否则输出分成两半的最小差距. 思路:将提供的整袋钱的总价取一半来进行01背包,如果能分出出来,就是最佳分法.否则背包容量为一半总价的 ...

  8. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  9. Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)

    A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descript ...

随机推荐

  1. windows下svn自动更新

    配置hooks下post-commit.bat文件,文件内容如下 @echo offSET REPOS=%1SET REV=%2SET DIR=%REPOS%/hooksSET PATH=%PATH% ...

  2. wechat

  3. Scss sass

    http://www.ruanyifeng.com/blog/2012/06/sass.htmlscss 声明:1,$blue : #1875e7;2,.class1 { border: 1px so ...

  4. jsoup Cookbook(中文版)--爬虫(java)

    转载:http://www.open-open.com/jsoup/ 目录: 入门 解析和遍历一个html文档 输入 解析一个html字符串 解析一个body片断 根据一个url加载Document对 ...

  5. DotNetBar v14.0.0.3 Fully Cracked

    更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=14.0.0.3 如果遇到破解问题可以与我 ...

  6. RPI学习--wiringPi_setups

    reference: http://wiringpi.com/reference/setup/ There are four ways to initialise wiringPi. wiringPi ...

  7. libbspatch.so

    http://www.zhihu.com/question/21154099 http://blog.csdn.net/hmg25/article/details/8100896 91助手和Googl ...

  8. 生成Apk遇到的问题

    conversion to dalvik format failed with error 1 android proguard keep Parameterized class

  9. SQL2008:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。

    错误: 解决方案: 1.查看服务是否开启,如果没有开启,请开启服务. 2.服务器名称栏:格式:主机名\实例名或者ip\实例名 如:10.10.4.81\SQLSERVER

  10. linux基础命令学习(一)

    pwd 输出当前工作路径tree 以树状图列出目录的内容ctrl+c 取消命令的执行clear 清空屏幕ls 列出文件目录 蓝色是目录,白色是普通文件alias cls=clear 别名终端:本地终端 ...