LeetCode #62 Unique Paths
2021-04-23 本文已影响0人
刘煌旭


/**
* Abstract: A DP problem, immediately from the problem specs.
*/
int uniquePaths(int m, int n) {
int **dp = (int**)malloc((m + 1) * sizeof(*dp));
for (int i = 1; i <= m; i++) {
dp[i] = (int*)malloc((n + 1) * sizeof(int));
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];
}