赞
踩
*/
- public class MaritixMin {
- public static int minDis(int[][] m) {
- int [][] dp = new int[4+1][4+1];
- dp[0][0] = m[0][0];
- for (int i = 1; i < m.length; i++) {
- for (int j = 1; j < m[0].length; j++) {
- if(i==1) {
- dp[i][j] = dp[i][j-1]+m[i][j];
- }else if(j==1) {
- dp[i][j] = dp[i-1][j] +m[i][j];
- }else {
- int temp1 = dp[i][j-1]+m[i][j];
- int temp2 = dp[i-1][j]+m[i][j];
- int min = temp1<temp2?temp1:temp2;
- dp[i][j] = min;
- }
-
- }
-
- }
-
- return dp[m[0].length-1][m.length-1];
- }
-
- public static void main(String[] args) {
- int[][] martix = {{0,0,0,0,0},
- {0,1,3,5,9},
- {0,8,1,3,5},
- {0,5,0,6,1},
- {0,8,8,4,0}};
- System.out.println("最右下的最短路径为:"+minDis(martix));
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。