关闭

POJ 1154 LETTERS DFS+回溯

1236人阅读 评论(0) 收藏 举报

 

第一次使用回溯+DFS,学习
LETTERS
Time Limit: 1000MS   Memory Limit: 10000K



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.

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.

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 6
HFDFFB
AJHGDH
DGAGEH

Sample Output

6
 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2417438次
    • 积分:27324
    • 等级:
    • 排名:第213名
    • 原创:383篇
    • 转载:106篇
    • 译文:3篇
    • 评论:653条
    博客专栏
    最新评论