类似
leetcode leetcode62. 不同路径;63. 不同路径 II
机器人从(1,1)到(m,n)的问题;
进阶:中间家障碍物不可进
java 代码
import java.io.*;
import java.lang.*;
class Main{
static int n = 0, R = 0, C = 0, N = 110;
static int[][] nums = new int[N][N];
static int[][] max = new int[N][N];
static int getMax(){
for(int i = 1; i <= R; ++i){
for(int j = 1; j <= C; ++j){
max[i][j] = Math.max(max[i - 1][j], max[i][j - 1]) + nums[i][j];
}
}
return max[R][C];
}
public static void main(String[] args)throws Exception{
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
n = Integer.valueOf(buf.readLine());
while(n-- != 0){
String[] params = buf.readLine().split(" ");
R = Integer.valueOf(params[0]);
C = Integer.valueOf(params[1]);
for(int i = 1; i <= R; ++i){
String[] info = buf.readLine().split(" ");
for(int j = 1; j <= C; ++j){
nums[i][j] = Integer.valueOf(info[j - 1]);
}
}
int res = getMax();
System.out.println(res);
}
}
}