【DFS 回溯】HDU 1045 Fire Net
来源:互联网 发布:疯狂粤语 粤知一二 编辑:程序博客网 时间:2024/05/16 07:13
题目链接:点这里
数据量比较小,可以直接深搜水过。
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>using namespace std;char s[10][10];int dirx[] = {0,0,-1,1};int diry[] = {1,-1,0,0};int n, maxx = -0x3f3f3f3f;bool fit(int xx, int yy){ if(xx >= 0 && xx < n) if(yy >= 0 && yy < n) if(s[xx][yy] != 'X') return true; return false;}bool isok(int x, int y){ for(int i = 0; i < 4; i ++){ int newx = x, newy = y; while(1){ newx = newx + dirx[i], newy = newy + diry[i]; if(!fit(newx, newy)) break; if(s[newx][newy] == 'D') return false; } } return true;}void dfs(int cnt){ if(cnt > maxx) maxx = cnt; for(int i = 0; i < n; i ++){ for(int j = 0; j < n; j ++){ if(s[i][j] == '.' && isok(i, j)){ s[i][j] = 'D'; dfs(cnt + 1); s[i][j] = '.'; } } }}int main(){ while(scanf("%d", &n) != EOF && n){ maxx = -0x3f3f3f3f; memset(s, 0, sizeof(s)); getchar(); for(int i = 0; i < n; i ++) gets(s[i]); dfs(0); printf("%d\n", maxx); } return 0;}
0 0
- 【DFS 回溯】HDU 1045 Fire Net
- HDU 1045 Fire Net(DFS回溯)
- hdu 1045 Fire Net(DFS+回溯)
- HDU-1045 Fire Net(DFS+回溯)
- -----暴力dfs+回溯 hdu 1045-Fire Net
- HDOJ Fire Net 1045【DFS+回溯】
- hdu 1045 Fire Net-dfs
- hdu 1045 Fire Net dfs
- 【DFS】hdu 1045 Fire Net
- hdu 1045 Fire Net(dfs)
- HDU 1045 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 Fire Net(dfs)
- HDU 1045 Fire Net dfs
- hdu-1045 Fire Net(DFS)
- MFC不同对话框之间的数据传递
- HDU 1513 Palindrome
- (25)ExtJS之面板Panel
- Android中的HAL相关库搜索机制和原理学习
- aoj连通图判断集合个数
- 【DFS 回溯】HDU 1045 Fire Net
- 关于red5搭建流媒体服务器(毕业设计跟进)
- delphi注册类信息 根据类名创建实例
- 【LeetCode】Reverse Words in a String
- Android 自定义当ScrollView里面嵌套GridView计算高度并获得焦点
- cvFindContours内存不能随便释放掉~
- 输入悬停提示JS组件
- 思考
- I/O(二)FileReader和FileWriter和PrintWriter