【转】http://blog.csdn.net/zxy_snow/article/details/5947160
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int visit[30];
int n,m;
int step[8] = {1,0,-1,0,0,1,0,-1};
int num[100][100],cou = 1,mmax = 0;;
void DFS(int i, int j)
{
for( int k=0; k<8; k+=2)
{
int a = i+step[k];
int b = j+step[k+1];
if( a>=1 && a<=n && b>=1 && b<=m && !visit[num[a][b]] )
{
visit[num[a][b]] = 1;
cou++;
DFS(a,b);
if( cou > mmax )
mmax = cou;
cou--;
visit[num[a][b]] = 0;
}
}
}
int main(void)
{
char str[100];
while( cin >> n >> m )
{
getchar();
memset(visit,0,sizeof(visit));
cou = 1; mmax = 1;
for(int i=1; i<=n; i++)
{
gets(str);
for(int k=0; k<m; k++)
num[i][k+1] = str[k] -'A' + 1;
}
visit[num[1][1]] = 1;
DFS(1,1);
cout << mmax << endl;
}
return 0;
}
分享到:
相关推荐
poj 2488——dfs深度优先遍历 //给行数列数,求问能否遍历,给出字典序的一种遍历
NULL 博文链接:https://128kj.iteye.com/blog/1752661
NULL 博文链接:https://128kj.iteye.com/blog/1754177
NULL 博文链接:https://128kj.iteye.com/blog/1753387
NULL 博文链接:https://128kj.iteye.com/blog/1749213
NULL 博文链接:https://128kj.iteye.com/blog/1744222
NULL 博文链接:https://128kj.iteye.com/blog/1759266
NULL 博文链接:https://128kj.iteye.com/blog/1750462
NULL 博文链接:https://128kj.iteye.com/blog/1754170
NULL 博文链接:https://128kj.iteye.com/blog/1757060
NULL 博文链接:https://128kj.iteye.com/blog/1744555
NULL 博文链接:https://128kj.iteye.com/blog/1772172
twilight-poj-solutionPOJ () solution by twilight想当年要找一题的分析, 解答实在太难了现在都是开源的时代了, 干脆把Archive放到GitHub上, 供后来人参考.POJ ID: 部分题解: 转载请注明出处~
北大POJ3733-Changing Digits【DFS+强剪枝】 解题报告+AC代码
北大POJ1020-Anniversary Cake 解题报告+AC代码
北大POJ3373-Changing Digits【DFS+强剪枝】 解题报告+AC代码
北大POJ3009-Curling 2.0【DFS+Vector+回溯+剪枝】 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
北大POJ1691-Painting A Board 【拓扑+DFS】 解题报告+AC代码
NULL 博文链接:https://128kj.iteye.com/blog/1746750