hdu1045 Fire Net(dfs水)
来源:互联网 发布:凉宫春日 知乎 编辑:程序博客网 时间:2024/05/29 15:31
尼玛啊,一道很普通的深搜居然因为括号问题改了这么长时间,自己改代码的能力好低啊。。。
不过通过本题还是能感觉到dfs的强大,一个while居然可以遍历几乎整个图。。。
#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <iostream>using namespace std;const int N = 30;const int INF = 1000000;int Map[N][N];int n, maxx;int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};void dfs(int sum){ int i, j, k, flag; maxx = max(maxx, sum); for(j = 1; j <= n; j ++) for(k = 1; k <= n; k ++) { if(Map[j][k] == 0) //0 空地 1 墙 2 碉堡 -1 边界外 { flag = 1; for(i = 0; i < 4; i ++) { int xx = j; int yy = k; while(1) { xx = xx + dir[i][0]; yy = yy + dir[i][1]; if(Map[xx][yy] == 2) { flag = 0; break; } else if(Map[xx][yy] == 1 || Map[xx][yy] == -1) break; } } if(flag) { Map[j][k] = 2; dfs(sum + 1); Map[j][k] = 0; } } }}int main(){ // freopen("in.txt", "r", stdin); int i, j; char a; while(~scanf("%d", &n) && n) { maxx = 0; memset(Map, -1, sizeof(Map)); for(i=1; i<=n; i++) for(j=1; j<=n; j++) { cin >> a; if(a == '.')Map[i][j] = 0; else Map[i][j] = 1; } dfs(0); printf("%d\n", maxx); } return 0;}
0 0
- hdu1045 Fire Net(dfs水)
- HDU1045 Fire Net(dfs)
- HDU1045:Fire Net(DFS)
- HDU1045:Fire Net(DFS)
- HDU1045 Fire Net 【DFS】
- HDU1045 Fire Net(DFS)
- HDU1045 Fire Net DFS
- hdu1045 Fire Net (dfs)
- hdu1045 Fire Net(dfs)
- HDU1045 Fire Net(DFS枚举)
- HDU1045 Fire Net(深搜DFS)
- HDU1045 Fire Net 暴力搜索DFS
- hdu1045 Fire Net —— dfs
- HDU1045 - Fire Net (深搜)
- HDU1045-Fire Net(回溯)
- HDU1045 Fire Net
- hdu1045 Fire Net
- hdu1045---Fire Net
- 51nod 1007 正整数分组 (类01背包问题)
- Git 学习笔记
- git 版本控制和SourceTree的安装使用 eclipse 的egit 插件安装使用
- 1080. Graduate Admission (30)
- SCU 3172-Fisherman(0-1背包)
- hdu1045 Fire Net(dfs水)
- 实战——简易计算器
- javascript & DHTML cookbook摘抄
- LeetCode:Majority Element
- mysql集群搭建教程-基础篇
- NSDate 实现时间格式刚刚、几分钟前、几小时前、昨天、MM-dd HH:mm:ss
- 2015年度总结
- Postgresql 创建用户 可登录 设置权限 配置 远程登录 修改默认用户密码
- SpringMVC + Hibernate + Framewoker 示例