随笔分类 - 背包
hdu 4501 小明系列故事——买年货
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4501多维背包代码:#include<iostream>#include<cmath>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<stack>#include<queue>#include<set>#include<map>#include<algorithm>#define
阅读全文
E. Coin Troubles
摘要:http://codeforces.com/contest/284/problem/E思维很重要呀 原来是一个背包呀代码:#include<iostream>#include<cmath>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<stack>#include<queue>#include<map>#include<set>#include<algorithm>
阅读全文
zoj 2955 Interesting Dart Game
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1954这个题给我们的感觉就是完全背包 但是N太大 需要用鸽巢原理优化先将a(1---n)排序(a1,a2,a3.......an) 每个数选择的个数为(k1,k2,k3........kn)(ki可以为0)使得 k1*a1+k2*a2+k3*a3+.........+kn*an==N则 (k1+k2+k3+.....kn-1)<an用反证法证明: 假如说sum=(k1+k2+k3+.....kn-1)>=an 那么根据鸽巢原理 在前sum个数里面 一定存在 连续的
阅读全文
1570. Eating High
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1570此题如果只求最少花费的话,就可以简单的dp或是背包就可以了难就难在在选择路径上有困难 应该在记录路径时 记下所有可能是最优的路径 排除一定不是最优的路径然后选择一条最优的总路径代码:#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<set>
阅读全文
poj 2754 Similarity of necklaces 2
摘要:http://poj.org/problem?id=2754先把low--up 转化为0--(up-low)然后变成背包 背包的关键在于多重背包用二进制优化代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#includ
阅读全文
浙公网安备 33010602011771号