问题描述
解题思路
还是找递推关系:
\(dp_{mn} = dp_{(m-1)n} + dp_{m(n-1)}\)
代码
#include <vector>
using std::vector;
class Solution {
public:
int uniquePaths(int m, int n) {
vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
dp[1][1] = 1;
// dp[1][2] = 1;
// dp[2][1] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 && j == 1)
dp[i][j] = 1;
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[m][n];
}
};
标签:paths,int,62,vector,unique,dp
From: https://www.cnblogs.com/zwyyy456/p/16755938.html