上一页 1 ··· 7 8 9 10 11 12 下一页
摘要: http://acm.nyist.net/JudgeOnline/problem.php?pid=4560/1背包问题View Code 1 #include <iostream> 2 #define maxn 100005 3 using namespace std; 4 int ans[maxn], v[maxn]; 5 int main() 6 { 7 long t, n, i, j, sum, m; 8 cin >> t; 9 while(t--)10 {11 cin >> n;12 sum = 0;13 ... 阅读全文
posted @ 2012-08-31 12:01 YORU 阅读(157) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1059很弱....时间是750ms....View Code 1 #include <iostream> 2 #define n 7 3 #define maxn 125005 4 using namespace std; 5 int main() 6 { 7 long t=0, i, j, l, sum, ans[maxn], v[n], num[n], m; 8 while(1) 9 {10 t++;11 sum = 0;12 fo... 阅读全文
posted @ 2012-08-31 10:20 YORU 阅读(201) 评论(0) 推荐(0)
摘要: 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 阅读(152) 评论(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 阅读(146) 评论(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)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1203依旧是0/1背包的问题. 水题,秒杀之。。O(∩_∩)O哈哈~View Code 1 #include <stdio.h> 2 #define maxn 10005 3 double ans[maxn], w[maxn]; 4 int v[maxn]; 5 int main() 6 { 7 int n, m, i, j; 8 while(~scanf("%d%d",&m,&n),n||m) 9 {10 for(i = 0; i < n; i++)11 阅读全文
posted @ 2012-08-29 21:36 YORU 阅读(156) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2602水题一道,依旧是0/1背包的问题。。。加深理解O(∩_∩)O~View Code 1 #include <iostream> 2 #define maxn 1005 3 using namespace std; 4 long ans[maxn], v[maxn], w[maxn]; 5 int main() 6 { 7 long t, n, m, i,j; 8 cin >> t; 9 while(t--)10 {11 cin >> n >> m;12 .. 阅读全文
posted @ 2012-08-29 20:38 YORU 阅读(131) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2546依旧是0/1背包的问题。 只是 v,w相同。View Code 1 #include <iostream> 2 #include <algorithm> 3 #define maxn 1005 4 using namespace std; 5 int f[maxn],v[maxn]; 6 7 int main() 8 { 9 int n, m, i, j;10 while(cin >> n, n)11 {12 for(i = 0; i < n; i++)13 . 阅读全文
posted @ 2012-08-29 17:12 YORU 阅读(184) 评论(0) 推荐(0)
摘要: http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=4183初学 0/1 背包,准备开始看背包.....View Code 1 #include <iostream> 2 #define maxn 1001 3 using namespace std; 4 int f[maxn][maxn], v[maxn], w[maxn], mark[maxn]; 5 int main() 6 { 7 int i, j, n, m, l, now; 8 cin >> n >> m; 9 for(i = 0; i <= 阅读全文
posted @ 2012-08-29 15:51 YORU 阅读(159) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 下一页