
背包
synapse7
这个作者很懒,什么都没留下…
展开
-
UVa 562 Dividing coins (0-1背包&等价转化)
562 - Dividing coinsTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=503It's commonly known that the Dutch原创 2013-10-07 14:53:04 · 1251 阅读 · 0 评论 -
POJ 2184 Cow Exhibition (想法题&双变量0-1背包)
http://poj.org/problem?id=2184dp[s]表示当TS=s时,TF的最大值。if (s > 0){ for (j = Max; j >= Min; --j) dp[j + s] = max(dp[j + s], dp[j] + f);///dp[s]表示当TS=s时,TF的最大值 Max += s;}else{ if (f <=原创 2014-02-20 09:44:57 · 890 阅读 · 0 评论 -
HDU 2955 Robberies (想法题&0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955如何变形呢??int _01pack(int n, int maxw){ memset(dp, 0, sizeof(dp)); dp[0] = 1.0;///初始化这个 int i, j; for (i = 0; i < n; ++i) for (j = maxw; j >=原创 2014-02-20 06:54:33 · 843 阅读 · 0 评论 -
HDU 2546 饭卡 (需要一些思考的0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2546先给菜价排个序,然后:printf("%d\n", m 完整代码:/*62ms,240KB*/#include#include#includeusing namespace std;const int mx = 1005;int w[mx], dp[mx];原创 2014-02-20 06:03:39 · 796 阅读 · 0 评论 -
HDU 2602 Bone Collector (经典0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2602/*31ms,240KB*/#include#include#includeusing namespace std;const int mx = 1005;int w[mx], v[mx], dp[mx];void _01pack(int n, int maxw){ me原创 2014-02-20 05:38:11 · 1073 阅读 · 0 评论 -
POJ 3211 Washing Clothes (平衡划分&01背包)
http://poj.org/problem?id=3211既然两个人可以同时洗同色的衣服,那么对每种颜色进行分析,转化为在sumtime/2的时间内能洗至多多久的衣服,则洗这种颜色的衣服至少用时sumtime-01pack(sumtime/2)完整代码:/*32ms,968KB*/#include#include#include#includeusing原创 2014-02-27 21:14:42 · 924 阅读 · 0 评论 -
POJ 1014 / HDU 1059 Dividing (多重背包&剪枝&单调队列)
http://poj.org/problem?id=1014参考了http://poj.org/showmessage?message_id=173435完整代码: /*0ms,376KB*/#include#includeconst int mx = 7;const int mxw = 1300;int m[mx], dp[mxw], deq[mxw],原创 2014-02-27 18:44:07 · 1045 阅读 · 0 评论 -
POJ 1276 Cash Machine (多重背包&单调队列)
http://poj.org/problem?id=1276模板题。完整代码:/*110ms,4316KB*/#include#includeconst int mx = 1005;const int mxw = 1000005;int w[mx], m[mx], dp[mxw], deq[mxw], deqv[mxw];int solve(int m原创 2014-02-27 14:48:50 · 1771 阅读 · 0 评论 -
HDU 2159 FATE (二维费用完全背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2159参考《背包九讲》第5讲注意循环时,每次先杀一只怪,再选择不同的忍耐消耗。完整代码:/*0ms,276KB*/#include#include#includeusing namespace std;const int maxn = 105;int exp[max原创 2014-02-24 10:13:29 · 915 阅读 · 0 评论 -
Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)
A. Cut Ribbonhttp://codeforces.com/problemset/problem/189/Atime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-29 21:19:33 · 2568 阅读 · 0 评论 -
UVa 674 Coin Change (完全背包&最优解的方案数)
思路:从上往下分析,嗯。。。一个五叉树。所以干脆从下往上递推:dp[i] = dp[i] + dp[i - coin[k]]完整代码:原创 2013-09-23 00:00:47 · 1410 阅读 · 0 评论 -
UVa 147 Dollars (完全背包)
147 - DollarsTime limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83和UVa 357一样。注意所有数除以5再算。完整代码:/*0.019s*/#in原创 2013-11-19 09:00:53 · 1187 阅读 · 0 评论 -
HDU 2639 Bone Collector II (0-1背包第k优解)
http://acm.hdu.edu.cn/showproblem.php?pid=2639参考背包九讲9.5节,注意合并单调队列的技巧(末尾加一个-1标记)完整代码:/*109ms,488KB*/#include#include#include#includeusing namespace std;int w[105], v[105], dp[1005原创 2014-02-20 21:36:35 · 944 阅读 · 0 评论 -
UVa 357 Let Me Count The Ways (完全背包)
357 - Let Me Count The WaysTime limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=293思路:dp[i] += dp[i - coin[原创 2013-11-19 08:48:00 · 2096 阅读 · 0 评论 -
O(NV)的完全背包算法 及 HDU 4508 湫湫系列故事——减肥记I (完全背包)
介绍:完全背包:有N种物品和一个容量为V的背包,每种物品都有无限件可用。放入第i种物品的价值是Wi,所占空间是Ci。求解:将哪些物品装入背包,可使这些物品体积总和不超过背包容量,且价值总和最大。题目可以转化为在Σ(i=1~N) kiCi 思路:temp = f[j - c[i]] + w[i];if (f[j] < temp) f[j] = temp;读原创 2013-07-31 09:42:53 · 1206 阅读 · 0 评论 -
UVa 624 CD (0-1背包)
624 - CDTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=565You have a long drive by car ahead. You have a原创 2013-10-07 10:35:10 · 1819 阅读 · 0 评论 -
UVa 10664 Luggage (0-1背包)
10664 - LuggageTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1605Peter and his friends are on holiday, s原创 2013-10-07 15:44:33 · 1647 阅读 · 0 评论 -
UVa 10130 SuperSale (0-1背包)
10130 - SuperSaleTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1071There is a SuperSale in a SuperHiperM原创 2013-10-07 15:12:54 · 1203 阅读 · 0 评论 -
HDU 2126 Buy the souvenirs (贪心&0-1背包最优解的个数)
http://acm.hdu.edu.cn/showproblem.php?pid=2126由于身上的钱相当于背包容量,价格相当于重量,由于我们要买尽量多的物品,所以每件物品的价值就为1在价值都相等的情况下,我们可以用贪心的思想求出最多能买多少件物品——排个序就行了最后就是怎么就最优解的方案数,如下:for (j = 0; j <= maxw; ++j) selection原创 2014-02-20 15:59:13 · 978 阅读 · 0 评论