摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1171我坑在了两个地方, 首先看到-1的时候就结束, 然后就是-1了. 再是数组的范围我一直以为是 100*1000 的, 结果还是小.这题为多重背包, 其中 V , W 的值是相同的. 是不是可以用什么单调队列优化?.....View Code 1 #include <iostream> 2 #define maxn 125005 3 using namespace std; 4 long ans[maxn], v[maxn], num[maxn], n, m; 5 void complete_ 阅读全文
posted @ 2012-08-30 21:24 YORU 阅读(151) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2191题目是多重背包的题目,但是我们可以写成是0/1背包的格式。0/1背包的代码:View Code 1 #include <iostream> 2 #define maxn 101 3 using namespace std; 4 int ans[maxn], v[maxn], w[maxn], num[maxn]; 5 int main() 6 { 7 int i, j, l, n, m, t; 8 cin >> t; 9 while(t--)10 {11 ... 阅读全文
posted @ 2012-08-30 16:46 YORU 阅读(412) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1114在0/1背包中有说,当只有f[0]=0,其他值为-∞时,可以求到恰好是装满时的最大值.这题应用这个原理,即只有f[0]=0,其他的都不为0,应该讲它设置为+∞,则恰好可以求到装满时的最小指.View Code 1 #include <iostream> 2 #define maxn 10005 3 #define M 505 4 using namespace std; 5 int ans[maxn], v[M], w[M]; 6 int main() 7 { 8 int t, n, m, 阅读全文
posted @ 2012-08-30 11:13 YORU 阅读(145) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1248完全背包....View Code 1 #include <iostream> 2 #define maxn 10005 3 using namespace std; 4 int ans[maxn],v[3]; 5 int main() 6 { 7 int n, t, i, j; 8 v[0] = 150; 9 v[1] = 200;10 v[2] = 350;11 cin >> t;12 while(t--)13 {14 cin... 阅读全文
posted @ 2012-08-30 09:21 YORU 阅读(197) 评论(0) 推荐(0)