随笔分类 -  背包

摘要:http://poj.org/problem?id=1252题意:给出六种钱币(面值都在1-100)求出组合成1-100的最少步数和(这里可以减);思路:完全背包;代码:View Code #include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>using namespace std;#define mm 9999999int dp1[2100]; //这里刚开始开到200,会WA,要开大一点int a[7] 阅读全文
posted @ 2012-04-13 21:22 LT-blogs 阅读(278) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1742背包真的很神奇啊;题意:给你一些硬币,每种硬币有一定的价值和数目,用这些硬币能组合成多少小于s的组合;思路:采用背包,在这里要加一个记录个数的数组num[],这样就变成二维的了,减少了时间;View Code #include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int main(){ int n,s,ans[100010],num[100010],val[110 阅读全文
posted @ 2011-12-07 20:55 LT-blogs 阅读(219) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2639题意:给你一些Bone和一个背包体积,求第K大的价值;思路:采用了三维的数组第三维是存(1-k)大的值的:View Code #include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int val[120],vv[120];int ans[1200][120],a[120],b[120];int main(){ int q,n,v,k 阅读全文
posted @ 2011-12-06 20:17 LT-blogs 阅读(211) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3449这个题AC的有点稀里糊涂(是1A过的),采用的01背包的方法;思路:定义了两个数组用来存储最终结果和但购买这一组的篮子是的价值,然后a[j]=max(a[j],b[j-link[i].pi]);把最终结果给a[],每次找完一组的时候更新一下;View Code 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdlib> 5 #include<cs 阅读全文
posted @ 2011-11-25 21:57 LT-blogs 阅读(302) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1059http://poj.org/problem?id=1014多重背包这个题有两种AC的方法一种是采用多重背包的方法,但是这个方法会超时,所以就加了一个取模(这是错误的地方)来减少时间,这个方法可以AC,但却是错误的 12 0 0 0 0 1 这组数据就不能正确的出结果;View Code 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 u 阅读全文
posted @ 2011-11-25 20:56 LT-blogs 阅读(274) 评论(0) 推荐(0)