华为9.8机试第二题
有懂得人帮我看看为啥一直28%过不去
package test;
import java.util.Scanner;
public class huawei_2 {
public static int minstep(int m, int n, int[][] nums) {
int[][] f=new int[m][n];
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
if (i==0 && j==0)
f[i][j]=0;
else{
f[i][j]=Integer.MAX_VALUE;
for (int i1=0;i1<i;i1++) {
if (nums[i1][j]>=(i-i1)) {
f[i][j]=Math.min(f[i][j], f[i1][j]+1);
}
}
for (int j1=0;j1<j;j1++) {
if (nums[i][j1]>=(j-j1)) {
f[i][j]=Math.min(f[i][j], f[i][j1]+1);
}
}
}
}
}
return f[m-1][n-1];
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
String[] ss=s.split(",");
int m = Integer.parseInt(ss[0]);
int n = Integer.parseInt(ss[1]);
int[][] nums=new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
nums[i][j] = in.nextInt();
}
}
System.out.println(minstep(m,n,nums));
in.close();
}
}
#华为机试题##华为##笔经#