//平分硬币问题 //对sum/2进行01背包,sum-2*dp[sum/2] #include <iostream> #include <cstring> #include <algorithm> using namespace std; ],dp[]; int main() { int n,m,sum,sum1; cin>>n; while(n--) { cin>>m; sum=; ;i<=m;i++) { cin>>val…
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 ],dp[N]; int…
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great lengt…
  Dividing coins  It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great le…
题意:一袋硬币两人分,要么公平分,要么不公平,如果能公平分,输出0,否则输出分成两半的最小差距. 思路:将提供的整袋钱的总价取一半来进行01背包,如果能分出出来,就是最佳分法.否则背包容量为一半总价的包能装下的硬币总值就是其中一个人能分得的最多的钱了,总余下的钱减去这包硬币总值.(只需要稍微考虑一下总值是奇数/偶数的问题) #include <iostream> #include <stdio.h> #include <string.h> #include <cm…
题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum,   A,B其中必有一人获得的钱小于等于sum/2,另一人获得的钱大于等于sum/2.   因此用sum/2作为背包容量对n个硬币做01背包处理,   所能得到的最大容量即为其中一人获得的钱数. #include <iostream> #include <cstdio> #include <cstring> #includ…
题目链接:https://vjudge.net/contest/103424#problem/E 题目大意: 给你一堆硬币,让你分成两堆,分别给A,B两个人,求两人得到的最小差. 解题思路: 求解两人分得钱币的最小差值,巧妙地转化为01背包问题. sum代表这堆钱币的总价值,ans=sum/2,求出得钱较少的人的钱币总量,即在这堆钱币中挑选出一定量的钱币,使得它的总值为小于或等于ans的最大值,即将它转化为01背包问题,背包容量为ans,每一个钱币看成价值与体积相等的物品. #include <…
It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great length and thus crea…
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 <…
题目描述:给出一些不同面值的硬币,每个硬币只有一个.将这些硬币分成两堆,并且两堆硬币的面值和尽可能接近. 分析:将所有能够取到的面值数标记出来,然后选择最接近sum/2的两个面值 状态表示:d[j]表示用当前给定的硬币是否可以凑得总面值j 转移方程:d[j]=d[ j-coin[i] ] 开始时只取出硬币coin[0],判断它是否能凑得总面值j 每新加入一个硬币coin[i]时,判断所有已经取出的硬币能否凑得总面值j #include <iostream> #include <cstdi…