题目 3035: LETTERS
题目描述:
(图片来源网络,侵删)
给出一个roe×col的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母。问最多可以经过几个字母。
代码:
package lanqiao; import java.util.*; public class Main { static int n; static int m; static char[][] arr; static int[][] check; //判断是否走过 static int count = 0; static int sum = 0; static int[] map = new int[200]; //判断是否重复 public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); arr = new char[n][m]; check = new int[n][m]; for(int i = 0;i count){ count = sum; } //左移 if (x - 1 >= 0 && check[x - 1][y] == 0 && map[arr[x - 1][y]] == 0) { check[x - 1][y] = 1; map[arr[x - 1][y]] = 1; sum++; dfs(x - 1, y); check[x - 1][y] = 0; map[arr[x - 1][y]] = 0; sum--; } //右移 if (x + 1 = 0 && check[x][y - 1] == 0 && map[arr[x][y - 1]] == 0) { check[x][y - 1] = 1; map[arr[x][y - 1]] = 1; sum++; dfs(x, y - 1); check[x][y - 1] = 0; map[arr[x][y - 1]] = 0; sum--; } //下移 if (y + 1(图片来源网络,侵删)
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。
还没有评论,来说两句吧...