书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

2012年3月28日

DFS解决任意组合原来这样简单

摘要: HDU 2660http://acm.hdu.edu.cn/showproblem.php?pid=2660题意就不说了,直接走代码。View Code #include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;#define max(a, b) (a>b?a:b)int V[21], W[21], Ans, N, K, L, i;void DFS(int p, int vv, 阅读全文

posted @ 2012-03-28 18:45 More study needed. 阅读(202) 评论(0) 推荐(0) 编辑

简单多重背包(每种物品选一次)

摘要: 先说一下多重背包问题。他是由完全背包而来的,但是不同的是,他的每件物品有一定的数量限量,而完全背包中每种物品可以有无限件。HDU 2660http://acm.hdu.edu.cn/showproblem.php?pid=2660题目大意:在N件物品中,最多可以选择K,在选择的K件物品中,总容量不能超过W.求选择的最大价值。本题就是一个任意组合问题了,当然除了这种解法以外还有一种解法。那就是DFS了。View Code #include<iostream>#include<cstdio>#include<cstring>#include<string& 阅读全文

posted @ 2012-03-28 18:09 More study needed. 阅读(205) 评论(0) 推荐(0) 编辑

回溯路径的记录

摘要: HDU 1016http://acm.hdu.edu.cn/showproblem.php?pid=1016题目大意:给定一个数N,从1到N的这些整数构成一个环,它的目的就是让你找出第相邻两个数都是素数的环。而且是所有的环。View Code #include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;int N;bool vis[21];int pre[21];bool prime[ 阅读全文

posted @ 2012-03-28 15:59 More study needed. 阅读(216) 评论(0) 推荐(0) 编辑

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!