#1349. LETTERS

LETTERS

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

描述

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.

翻译: 给出一个RS\red{R * S}的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母。问最多可以经过几个字母。

输入格式

The first line of the input contains two integers R and S, 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

提示

对于100%\red{100\%}的数据满足:1R,S20\red{1≤R,S≤20}

红盾周日上午班test

未参加
状态
已结束
规则
IOI
题目
6
开始于
2023-9-24 9:30
结束于
2023-9-24 12:30
持续时间
3 小时
主持人
参赛人数
7