
1 /* 2 * @Author: yaodaoteng 3 * @Date: 2020-11-26 21:03:52 4 * @LastEditors: yaodaoteng 5 * @LastEditTime: 2020-11-26 21:08:01 6 * @FilePath: \git\leetcode\62.不同路径.cpp 7 */ 8 /* 9 * @lc app=leetcode.cn id=62 lang=cpp 10 * 11 * [62] 不同路径 12 */ 13 14 // @lc code=start 15 class Solution { 16 public: 17 18 /* 19 动态规划 20 dp[i][j]表示表示到达点[i,j]的路径数 21 状态转移方程: 22 ①:i==0||j==0时,则·dp[i][j]=1,表示边界上的路径只有一条 23 ②:i!=0&&j!=0时,则dp[i][j]=dp[i-1][j]+dp[i][j-1],表示到达点[i,j]与该点正上和正右的点有关 24 */ 25 int uniquePaths(int m, int n) { 26 int dp[m][n]; 27 28 for (int i = 0; i < m;i++){ 29 for (int j = 0; j < n;j++){ 30 if(i==0||j==0) 31 dp[i][j] = 1; 32 else 33 dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; 34 } 35 } 36 return dp[m - 1][n - 1]; 37 } 38 }; 39 // @lc code=end
浙公网安备 33010602011771号