HDU 1045 Fire Net
2012-02-01 14:45
218 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1045
DFS
我的代码
DFS
我的代码
#include <stdio.h> const int N=5; char maze ; int vis ; int n,ans; int ok(int x,int y) { if (maze[x][y]=='X') return 0; int i; for (i=x+1;i<n && maze[i][y]!='X';i++) if (vis[i][y]) return 0; for (i=x-1;i>=0 && maze[i][y]!='X';i--) if (vis[i][y]) return 0; for (i=y+1;i<n && maze[x][i]!='X';i++) if (vis[x][i]) return 0; for (i=y-1;i>=0 && maze[x][i]!='X';i--) if (vis[x][i]) return 0; return 1; } void dfs(int p,int s) { if (p==n*n) { if (s>ans) ans=s; return; } int x=p/n,y=p%n; dfs(p+1,s); vis[x][y]=1; if (ok(x,y)) dfs(p+1,s+1); vis[x][y]=0; } int main() { int i; while (scanf("%d",&n),n) { ans=0; for (i=0;i<n;i++) scanf("%s",maze[i]); dfs(0,0); printf("%d\n",ans); } return 0; }
相关文章推荐
- 杭电 hdu 1045 Fire Net
- HDU 1045 Fire Net
- HDU-1045-fire net
- hdu1045 Fire Net
- HDU 1045 Fire Net【深搜】
- HDU 1045 Fire Net (dfs 或 二分图)
- HDU 1045 Fire Net
- HDU 1045 Fire Net(DFS)
- HDU 1045 Fire Net(行列匹配变形+缩点建图)
- HDU 1045 Fire Net【深搜】
- 【HDU 1045】Fire Net(DFS,check函数)
- hdu 1045 Fire Net
- hdu 1045 Fire Net(二分图匹配)
- HDU 1045 Fire Net
- hdu 1045 Fire Net(最大流)
- hdu1045 Fire Net(dfs)
- zoj 1002 && hdu 1045 Fire Net
- hdu 1045 || zoj 1002 Fire Net(搜索:DFS+水题)
- hdu 1045 Fire Net
- hdu 1045 Fire Net(DFS)