摘要: 这是一道有依赖的背包的经典题目,考虑到每个物品最多有两个子物品,最多会有四种状态,所以可以转化为01背包进行枚举状态View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 3250 4 #define M 65 5 int a[N]; 6 int s[M][4]; 7 int v[M][3]; 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int main()13 {14 int n,m;15 int i,j,k;16 int f;17.. 阅读全文
posted @ 2012-05-01 22:51 zhenhai 阅读(188) 评论(0) 推荐(0)
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191多重背包题目,转化为01背包求解View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 105 4 int a[N]; 5 int wei[N]; 6 int pri[N]; 7 int b[N]; 8 int max(int a,int b) 9 {10 return a>b?a:b;11 }12 int main()13 {14 int t;15 int n,m,i,j,k;16 scanf.. 阅读全文
posted @ 2012-05-01 20:44 zhenhai 阅读(177) 评论(0) 推荐(0)
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114这道题是要找最小的可能值,所以初始化的时候要注意一下不同。完全背包的题,要注意总结这些模版题View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define MAXA 1000000000 4 #define N 10005 5 #define M 505 6 int a[N]; 7 int wei[M]; 8 int val[M]; 9 int min(int a,int b)10 {11 return a<b 阅读全文
posted @ 2012-05-01 16:46 zhenhai 阅读(215) 评论(0) 推荐(0)
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602最基本的01背包问题,现在发现需要好好的搞搞基础题了,校赛的一个多重背包竟然没做出来。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 1005 4 int a[N]; 5 int v[N]; 6 int val[N]; 7 int max(int a,int b) 8 { 9 return a>b?a:b;10 }11 int main()12 {13 int t,n,i,j,k,m;14 阅读全文
posted @ 2012-05-01 15:12 zhenhai 阅读(183) 评论(0) 推荐(0)