原題下載
答案
import java.io.*;
import java.util.*;
public class barnjump {
static char[][] grid;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("barnjump.in"));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("barnjump.out")));
StringTokenizer st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
/* Read the input into the grid array. */
grid = new char[r][c];
for(int i = 0; i < r; i++) {
String s = br.readLine();
for(int j = 0; j < c; j++) {
grid[i][j] = s.charAt(j);
}
}
/* Compute the answer! */
pw.println(count(0,0));
pw.close();
}
public static int count(int x, int y) {
if(x == grid.length-1 && y == grid[x].length-1) {
/* We arrived at the destination. */
return 1;
}
/* Otherwise try all valid next moves and sum the total number of paths. */
int ret = 0;
for(int i = x+1; i < grid.length; i++) {
for(int j = y+1; j < grid[i].length; j++) {
if(grid[i][j] != grid[x][y]) {
ret += count(i, j);
}
}
}
return ret;
}
}
以上就是關于【USACO 2015 February Contest, Bronze Problem 3. Cow Hopscotch (Bronze)】的解答,如需了解學校/賽事/課程動態,可至翰林教育官網獲取更多信息。
往期文章閱讀推薦:
【組隊招募】經濟/數模競賽CNEC/IEO/SIC/HiMCM…組隊報名!
NOAI人工智能奧賽 2026-2027 活動章程出爐:新規則必看!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1