2012年7月19日

DFS专题 Fire Net

摘要: 这道题暴力秒过,以前在ZOJ上见过,当时不会,还以为不剪枝铁定超呢,结果纯暴力就过了。# include <cstdio># include <cstring># define N 4 + 3int n, ans;char g[N][N];bool check(int x, int y){ int i = x; if (g[x][y] != '.') return false; while (i <= n) { if (g[i][y] == 'X') break; else if (g[i][y] == (i-1)*n+y) ret 阅读全文

posted @ 2012-07-19 19:57 getgoing 阅读(245) 评论(0) 推荐(0) 编辑

DFS 专题 Tempter of the Bone

摘要: 这道题的剪枝:奇偶性,曼哈顿距离类型的。不剪会超时。# include <cstdio># include <cstring>using namespace std;# define N 7 + 3# define ABS(x) (((x)>0)?(x):(-(x)))int si, sj, gi, gj;int n, m, T;char g[N][N];bool vis[N][N];bool finished;const int dir[][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}};void dfs(int x, int y, in 阅读全文

posted @ 2012-07-19 17:32 getgoing 阅读(151) 评论(0) 推荐(0) 编辑

DFS 专题 Accepted Necklace

摘要: 这道题如果用 DFS 必须剪枝:剪掉重复的组合。DFS 枚举了所有的排列,实际上这道题只需要组合。View Code # include <cstdio># include <cstring># define N 20 + 5int ans;int n, k, vMax, v[N], w[N];bool vis[N];void dfs(int cur, int sum, int cnt, int weight){ if (weight > vMax) return ; if (cnt == k) ans = (sum > ans ? sum : ans); 阅读全文

posted @ 2012-07-19 17:02 getgoing 阅读(167) 评论(0) 推荐(0) 编辑

DFS 专题 Beat

摘要: HINT 误导人,水题。View Code # include <cstdio># include <cstring># define N 15 + 5int n, ans;int f[N][N];bool vis[N];void dfs(int cur, int cnt, int t){ if (cnt > ans) ans = cnt; for (int i = 0; i < n; ++i) if (vis[i] == false && f[cur][i] >= t) { vis[i] = true; dfs(i, cnt+1, f 阅读全文

posted @ 2012-07-19 16:36 getgoing 阅读(147) 评论(0) 推荐(0) 编辑

DFS 专题 N皇后

摘要: DFS 其实会超时的,打表。# include <cstdio># include <cstring># define N 10 + 5int n, ans;int solu[N];bool vis[N];void dfs(int cnt){ if (cnt == n) { ++ans; return ; } bool ok; for (int i = 1; i <= n; ++i) if (vis[i] == false) { ok = true; for (int j = 1; j <= cnt; ... 阅读全文

posted @ 2012-07-19 16:06 getgoing 阅读(207) 评论(0) 推荐(0) 编辑

DFS 专题 哈密顿绕行世界问题

摘要: 注意:标号后面是两个空格。# include <cstdio># include <cstring># include <algorithm>using namespace std;int n, m, adj[21][3];bool vis[21];int solu[22];void dfs(int cur, int cnt){ int t; for (int i = 0; i < 3; ++i) { t = adj[cur][i]; if (cnt == 20 && t == m) { printf("%d: ... 阅读全文

posted @ 2012-07-19 15:35 getgoing 阅读(415) 评论(0) 推荐(0) 编辑

DFS专题 下沙小面的(2)

摘要: 这道题目有问题,4WA :注意:对于每组测试,Lele都是在站点0拉上乘客的。最后看了题解,改了初始状态 AC 的。View Code # include <cstdio># include <cstdlib># include <cstring># define N 30 + 5int n, k;int g[N][N], des[N], min;bool vis[N];int cmp(const void *x, const void *y){ return *(int*)x - *(int*)y;}void dfs(int cnt, int u, int 阅读全文

posted @ 2012-07-19 00:16 getgoing 阅读(200) 评论(0) 推荐(0) 编辑

导航