左上角,走到右下角。每一条路径都记录当前路径的最小值t。用一个全局值res来记录最终的结果,当每一条路径走到右下角时,将t与res比较。
头和尾是确定的,中间怎么走是变化的,因此会涉及到回溯,需要一个同样大小的矩阵来记录走过的位置。
这里记录一下自己写的没有调通的代码,以后有时间再慢慢调。
public class demo02 {
int res = 0;
int[][] dic = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
int[][] v = new int[len1][len2];
public static void DFS(int i, int j, int t,int[][] A,int[][] v){
int len1 = A.length;
int len2 = A[0].length;
if(i == len1-1 && j == len2-1){
res = Math.max(res, t);
}
for(int index = 0; index<4; index++){
int x = i + dic[index][0];
int y = j + dic[index][1];
if(x>=0 && x<len1 && y>=0 && y<len2 && v[x][y]==0){
v[x][y]=1;
DFS(x,y,A[x][y],A,v);
v[x][y]=0;
}
}
}
public static void main(String[] args) {
v[0][0] = 1;
DFS(0,0,A[0][0],A,v);
}
}