hdu 1045 Fire Net(dfs)
2014-05-12 20:14
344 查看
The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least
one wall separating them.
题意:
在墙隔断的区域里, 每行每列都必须有一个blockhouses(碉堡);
代码如下~
起先判断的时候,把每行每列从0-n-1都判断了一下,第三个案例老是错,纠结了好久= =!我想应该是要是从头开始判断的话,先遇见X了,就会break掉了,就会少算了。。
智商是硬伤啊。。。。= =!各位机智的小伙伴们应该不会犯这种错吧。。。= =!我好笨。。。
one wall separating them.
题意:
在墙隔断的区域里, 每行每列都必须有一个blockhouses(碉堡);
代码如下~
起先判断的时候,把每行每列从0-n-1都判断了一下,第三个案例老是错,纠结了好久= =!我想应该是要是从头开始判断的话,先遇见X了,就会break掉了,就会少算了。。
智商是硬伤啊。。。。= =!各位机智的小伙伴们应该不会犯这种错吧。。。= =!我好笨。。。
#include <stdio.h> #include <string.h> char maze[6][6]; int max, n; int judge(int x) { int row, col, i; row=x/n; col=x%n; if(maze[row][col]!='.') return 0; for(i=row-1; i>-1; i--) { if(maze[i][col]=='#') return 0; if(maze[i][col]=='X') break; } for(i=col-1;i>-1; i--) { if(maze[row][i]=='#') return 0; if(maze[row][i]=='X') break; } return 1; } void dfs(int x, int cc) { int row, col; row=x/n; col=x%n; if(x==n*n) { if(max<cc) max=cc; return ; } if(judge(x)) { maze[row][col]='#'; dfs(x+1, cc+1); maze[row][col]='.'; } dfs(x+1,cc); } int main() { while(~scanf("%d%*c", &n),n) { int i; for(i=0; i<n; i++) gets(maze[i]); max=0; dfs(0,0); printf("%d\n",max); } return 0; }
相关文章推荐
- hdu 1045 Fire Net(dfs)
- HDU1045 Fire Net 暴力搜索DFS
- HDU - 1045 - Fire Net (DFS)
- hdu 1045 Fire Net(DFS+回溯)
- HDU1045 Fire Net(深搜DFS)
- HDU 1045 Fire Net(DFS)
- hdu 1045 Fire Net (dfs)
- 【DFS 回溯】HDU 1045 Fire Net
- hdu 1045 Fire Net (dfs || 二分图)
- hdu 1045 || zoj 1002 Fire Net(搜索:DFS+水题)
- hdu 1045 && zoj 1002 Fire Net(DFS && 二分图匹配)
- hdu 1045 Fire Net (最爱 DFS)
- HDU 1045 Fire Net(DFS)
- HDU 1045 Fire Net(DFS)
- hdu 1045 Fire Net(DFS)
- 【HDU 1045】Fire Net(DFS,check函数)
- HDU 1045 Fire Net(DFS)
- hdu1045 Fire Net(dfs)
- HDU 1045 Fire Net (DFS)
- hdu 1045 Fire Net(dfs)