编程题
年终奖

@SuppressWarnings({"all"})
public class Bonus {
public int getMost(int[][] board) {
int row = board.length;
int col = board[0].length;
for (int i = 1; i < col; i++) {
board[0][i] += board[0][i - 1];
}
for (int i = 1; i < row; i++) {
board[i][0] += board[i - 1][0];
}
for (int i = 1; i < row; i++) {
for (int j = 1; j < col; j++) {
board[i][j] += Math.max(board[i - 1][j], board[i][j - 1]);
}
}
return board[row - 1][col - 1];
}
}
迷宫问题

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
@SuppressWarnings({"all"})
class Node {
int x, y;
public Node(int x, int y) {
this.x = x;
this.y = y;
}
}
@SuppressWarnings({"all"})
public class Main {
private static void getMinPath(int[][] mat, int row, int col,
int x, int y, int[][] book, ArrayList<Node> path,
ArrayList<Node> minPath) {
if (x < 0 || x >= row || y < 0 || y >= col
|| book[x][y] == 1 || mat[x][y] == 1) {
return;
}
path.add(new Node(x, y));
book[x][y] = 1;
if (x == row - 1 && y == col - 1) {
if (minPath.isEmpty() || path.size() < minPath.size()) {
minPath.clear();
for (Node n : path) {
minPath.add(n);
}
}
}
getMinPath(mat, row, col, x + 1, y, book, path, minPath);
getMinPath(mat, row, col, x - 1, y, book, path, minPath);
getMinPath(mat, row, col, x, y - 1, book, path, minPath);
getMinPath(mat, row, col, x, y + 1, book, path, minPath);
path.remove(path.size() - 1);
book[x][y] = 0;
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str;
while ((str = reader.readLine()) != null) {
String[] arr = str.split(" ");
int row = Integer.parseInt(arr[0]);
int col = Integer.parseInt(arr[1]);
int[][] mat = new int[row][col];
for (int i = 0; i < row; i++) {
str = reader.readLine();
arr = str.split(" ");
for (int j = 0; j < col; j++) {
mat[i][j] = Integer.parseInt(arr[j]);
}
}
ArrayList<Node> path = new ArrayList<>();
ArrayList<Node> minPath = new ArrayList<>();
int[][] book = new int[row][col];
getMinPath(mat, row, col, 0, 0, book, path, minPath);
for (Node n : minPath) {
System.out.println("(" + n.x + "," + n.y + ")");
}
}
}
}