1 package leetcode; 2 3 public class demo_62 { 4 public int uniquePaths(int m, int n) { 5 //记录到达每一个位置所需的步数 6 int dp[][]=new int[m][n]; 7 for(int i=0;i<m;i++) { 8 for(int j=0;j<n;j++) { 9 //如果位置在上边界或者是左边界都只有一种方式到达 10 if(i==0||j==0) { 11 dp[i][j]=1; 12 } 13 else { 14 dp[i][j]=dp[i-1][j]+dp[i][j-1]; 15 } 16 } 17 } 18 System.out.println(dp[m-1][n-1]); 19 return dp[m-1][n-1]; 20 } 21 public static void main(String[] args) { 22 // TODO Auto-generated method stub 23 demo_62 d62=new demo_62(); 24 d62.uniquePaths(3, 7); 25 } 26 27 }
原文:https://www.cnblogs.com/Yshun/p/14851202.html