http://poj.org/problem?id=1154

#include<iostream>
using namespace std;
int bb[]={},s,r,sum=,s1=;
char aa[][];
int dir[][]={-,,,,,-,,};
void dfs(int a,int b)
{
int a1,b1; if(s1>sum)
sum=s1; //更新最大数值
for(int i=;i<;i++)
{ a1=a+dir[i][]; //用bb数组记录访问过的字母
b1=b+dir[i][];
if(a1>=&&a1<s&&b1>=&&b1<r&&!bb[aa[a1][b1]-'A'])
{
s1++;
bb[aa[a1][b1]-'A']=; //如果在这条单线上没有记录改字母被访问过,则总数++;
dfs(a1,b1); //第一个字母总要被访问,所以不用回溯; bb[aa[a1][b1]-'A']=; //回溯反标记
s1--; //临时记录恢复
} }
}
int main()
{
cin>>s>>r;
for(int i=;i<s;i++)
for(int j=;j<r;j++)
cin>>aa[i][j];
bb[aa[][]-'A']=;
dfs(,); cout<<sum<<endl; return ;
}

poj 1154 letters (dfs回溯)的更多相关文章

  1. 【POJ - 3009】Curling 2.0 (dfs+回溯)

    -->Curling 2.0 直接上中文 Descriptions: 今年的奥运会之后,在行星mm-21上冰壶越来越受欢迎.但是规则和我们的有点不同.这个游戏是在一个冰游戏板上玩的,上面有一个正 ...

  2. poj1270Following Orders(拓扑排序+dfs回溯)

    题目链接: 啊哈哈.点我点我 题意是: 第一列给出全部的字母数,第二列给出一些先后顺序. 然后按字典序最小的方式输出全部的可能性.. . 思路: 整体来说是拓扑排序.可是又非常多细节要考虑.首先要按字 ...

  3. 素数环(dfs+回溯)

    题目描述: 输入正整数n,把整数1,2...n组成一个环,使得相邻两个数和为素数.输出时从整数1开始逆时针排列并且不能重复: 例样输入: 6 例样输出: 1 4 3 2 5 6 1 6 5 2 3 4 ...

  4. NOJ 1074 Hey Judge(DFS回溯)

    Problem 1074: Hey Judge Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format: ...

  5. HDU 1016 Prime Ring Problem(经典DFS+回溯)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. HDU 2181 哈密顿绕行世界问题(经典DFS+回溯)

    哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. HDU1016 Prime Ring Problem(DFS回溯)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. uva 193 Graph Coloring(图染色 dfs回溯)

    Description You are to write a program that tries to find an optimal coloring for a given graph. Col ...

  9. P1074 靶形数独 dfs回溯法

    题目描述 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教,Z 博士拿出了他最近发明的“靶 ...

随机推荐

  1. pyinstaller打包py文件成exe文件时,出现ImportError: No module named 'pefile'错误解决办法!

    首先pyinstaller的安装与使用详见如下链接: 安装完成之后,命令行中输入pyinstaller之后,结果如下: ImportError: No module named 'pefile' 缺少 ...

  2. Tomcat启动过程源码解读

    根据Tomcat源码来看一下Tomcat启动过程都做了什么 部分代码为主要流程代码,删去了try-catch以及一些校验逻辑,方便理解主流程 先来一张启动过程时序图,了解一下启动顺序 Tomcat启动 ...

  3. uboot 添加hello命令

    平台:MPC8315(POWERPC) 1.在/common/ 目录下创建自己的文件,最好前缀为cmd_. cmd_hello.c ********************************** ...

  4. 错误代码: 1111 Invalid use of group function

    1.错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:update t_user_info t inner join t_pro_ ...

  5. RHEL64 缺少ISO 9660图像 安装程序试图挂载映像#1,在硬盘上无法找到该映像

    用光盘安装Linux,很容易,按照提示一步一步就好.如果没有光驱,只好想办法用硬盘或者U盘安装了. 首先说说怎样用U盘启动Linux的安装程序:1.将ISO镜像文件拷贝到U盘中,并解压到U盘根目录.将 ...

  6. TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9a7c0a1 转换为 spark.core.IViewport。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9aa90a1 转换为 spark.core.IViewport. ...

  7. iOS - Core Animation 核心动画的使用

    1.简单使用示例 1.1 时钟 QClockView.h @interface QClockView : UIView /// 创建时钟界面 + (instancetype)q_clockViewWi ...

  8. http协议的补充二

    一,浏览器到服务器request 1.1,浏览器里面的内容 请求(浏览器->服务器) GET /day09/hello HTTP/1.1 Host: localhost:8080 User-Ag ...

  9. JDK1.5-1.7的特性

    JDK1.5新特性: 1.自动装箱与拆箱 2.枚举(常用来设计单例模式) 3.静态导入  (import static java.lang.Math.*;) 4.可变参数 eg: public sta ...

  10. PyTorch官方中文文档:torch.nn

    torch.nn Parameters class torch.nn.Parameter() 艾伯特(http://www.aibbt.com/)国内第一家人工智能门户,微信公众号:aibbtcom ...