题意:
给定一堆硬币,然后将他们分成两部分,使得两部分的差值最小;输出这个最小的差值。
思路:
想了好久都没想到一个合适的状态转移方程。后面看了别人的题解后,才知道可以转成背包问题求解。
我们将所有的硬币和的一半作为背包容量,然后将硬币的代价看成其本身的面值。然后背包中能装的最大容量
就是其中一个人分得硬币数。
代码如下:
#include
#inclu...
分类:
其他好文 时间:
2014-12-18 00:19:24
阅读次数:
163
题目链接:POJ - 1742题目大意现有 n 种不同的硬币,每种的面值为 Vi ,数量为 Ni ,问使用这些硬币共能凑出 [1,m] 范围内的多少种面值。题目分析使用一种 O(nm) 的 DP (据说这是类多重背包?),枚举每一种硬币,对于每一种硬币 i 枚举每一个面值 j ,如果这个面值 j 使...
分类:
其他好文 时间:
2014-12-15 20:17:00
阅读次数:
166
1 #include 2 #include 3 int a[102],c[102],dp[100005]; 4 int max(int a,int b) 5 { 6 return a>b?a:b; 7 } 8 void CompletePack(int v,int w,int m) //完...
分类:
其他好文 时间:
2014-12-14 00:41:12
阅读次数:
119
这道题是典型的多重背包的题目,也是最基础的多重背包的题目题目大意:给定n和m, 其中n为有多少中钱币, m为背包的容量,让你求出在1 - m 之间有多少种价钱的组合,由于这道题价值和重量相等,所以就是dp[i] = i, 其中dp[i]表示当前背包容量为i 的时候背包能装的价值。题目思路: 模板 二...
分类:
其他好文 时间:
2014-12-11 22:13:32
阅读次数:
181
题目链接:点击打开链接
题意:n个硬币,给出每个硬币的价值,要求把这些硬币分成两组,使得两组的价值差尽量小。
可以发现如果可以平分,那么价值差肯定为0,那么依次从sum/2 --> 0 枚举i,如果用上述硬币的价值组合可以组成i 那么sum-i-i就是答案。如何判断是否对于一个数i用这些硬币可以凑出来,用背包判就可以了,注意是01背包。
#include
#include
#includ...
分类:
其他好文 时间:
2014-12-09 15:43:52
阅读次数:
122
题目:
有n种物品,每种物品有x, y两个价值,并且可以有无限多个。
给定s,使得(x1+x2+....)^2 + (y1+y2+....)^2 = s ^ 2。并且物品个数最少。
啊,一顿完全背包之后……再扫一顿……就可以了
#include
#include
#include
#include
#include
#include
#include
#include
#inclu...
分类:
其他好文 时间:
2014-12-08 19:38:49
阅读次数:
217
At the Department for Bills and Coins, an extension of today's monetary system has newly been proposed, in order to make it fit the new economy better. A number of new so called e-coins will be produc...
分类:
其他好文 时间:
2014-12-04 01:04:21
阅读次数:
229
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1398背包的硬币问题代码#include#includeint main(void){ int i,j,k,n; int dp[310]; int a[20]; for(i=1;i<...
分类:
其他好文 时间:
2014-11-25 23:29:42
阅读次数:
222
If you need any game cheat tool at free of cost without doing survey and other stuffs then directly get download from crazygamehacks.com .we provide y...
分类:
其他好文 时间:
2014-11-19 13:58:54
阅读次数:
508
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8611 Accepted Submission(s): 5851
Problem Description
People in Sil...
分类:
其他好文 时间:
2014-11-19 11:18:24
阅读次数:
137