poj 1154 LETTERS(深搜)
来源:互联网 发布:在数据库中 概念模型 编辑:程序博客网 时间:2024/06/12 01:16
LETTERS
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 8844 Accepted: 3962
Description
A single-player game is played on a rectangular board divided in R rows and C columns. There is a single uppercase letter (A-Z) written in every position in the board.
Before the begging of the game there is a figure in the upper-left corner of the board (first row, first column). In every move, a player can move the figure to the one of the adjacent positions (up, down,left or right). Only constraint is that a figure cannot visit a position marked with the same letter twice.
The goal of the game is to play as many moves as possible.
Write a program that will calculate the maximal number of positions in the board the figure can visit in a single game.
Before the begging of the game there is a figure in the upper-left corner of the board (first row, first column). In every move, a player can move the figure to the one of the adjacent positions (up, down,left or right). Only constraint is that a figure cannot visit a position marked with the same letter twice.
The goal of the game is to play as many moves as possible.
Write a program that will calculate the maximal number of positions in the board the figure can visit in a single game.
Input
The first line of the input contains two integers R and C, separated by a single blank character, 1 <= R, S <= 20.
The following R lines contain S characters each. Each line represents one row in the board.
The following R lines contain S characters each. Each line represents one row in the board.
Output
The first and only line of the output should contain the maximal number of position in the board the figure can visit.
Sample Input
3 6HFDFFBAJHGDHDGAGEH
Sample Output
6
tips:注意book数组的使用方式,简单深搜
#include<iostream>#include<cstring>#include<queue>using namespace std;char mapp[22][22];int n,m;int book[122];int dire[4][2]={-1,0,1,0,0,-1,0,1};int ans;void dfs(int x,int y,int step){ans=max(ans,step);for(int i=0;i<4;i++){int nx=dire[i][0]+x;int ny=dire[i][1]+y;if(nx<=0||nx>n||ny<=0||ny>m)continue;if(!book[mapp[nx][ny]]){book[mapp[nx][ny]]++;dfs(nx,ny,step+1); book[mapp[nx][ny]]--;} }}int main(){cin>>n>>m;getchar();for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>mapp[i][j];}getchar();}book[mapp[1][1]]++;dfs(1,1,1);cout<<ans<<endl;return 0;}
阅读全文
0 0
- poj 1154 LETTERS(深搜)
- poj 1154 LETTERS
- POJ 1154 LETTERS
- poj 1154 LETTERS
- poj 1154 LETTERS
- poj - 1154 - LETTERS
- poj LETTERS 1154
- poj 1154 LETTERS
- POJ 1154 LETTERS
- poj 1154 LETTERS
- poj 1154 LETTERS
- POJ 1154 LETTERS 笔记
- POJ 1154 LETTERS DFS+回溯
- poj 1154 LETTERS(DFS水!)
- poj 1154 LETTERS dfs入门题
- poj dfs相关之1154 LETTERS
- 1154:LETTERS
- 百练1154:LETTERS
- execute immediate 用法
- 非阻塞connect()
- 剑指offer--二叉树的镜像
- Ignite 保存web session
- 汇丰,用数字技术创新奇妙体验
- poj 1154 LETTERS(深搜)
- Mybatis Plugin插件安装破解及使用
- jsp中从session中取对象的属性做判断
- java项目中获取路径以及读写文件
- JSTL的c:forEach标签(${status.index})
- 七牛上传图片 使用线程
- 屏幕相关工具类
- 操作系统基础之存储器管理
- 面试题38:数字在排序数组中出现的次数