描述:
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.
输入:
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 first and only line of the output should contain the maximal number of position in the board the figure can visit.
样例输入:
3 6
HFDFFB
AJHGDH
DGAGEH
样例输出:
6
翻译:
字母
描述:
一个玩家的游戏就是在一个R行C列的木板上进行的。有一个字母(A-Z)被写在木板的每个位置上。
在游戏开始时有一个数字在木板的左上角(第一行第一列)。在每次的移动中,一个玩家能够移动一个数字到这四个中的一个位置(上下左右)。唯一矛盾的是同一个字母不能够到同一个位置两次。这个游戏的目的就是去尽可能多的移动。
写出一个程序能够计算出在木板上移动数字的最大值。
输入:
第一行输入包括两个整数R和C,被一个空格分隔开。R>=1,S<=20.
接下来每R行包含S个输出。每行就代表,木板上的一行。
输出:
第一行和输出的一行应该包含木板上的最大的位置。
样例输入:
3 6
HFDFFB
AJHGDH
DGAGEH
样例输出:
6