基本动态规划题
代码:
1 int uniquePaths(int m, int n) { 2 vector<int> sum(n, 0); 3 4 sum[n - 1] = 1; 5 for (int i = m - 1; i >= 0; i--) 6 for (int j = n - 2; j >= 0; j--) 7 sum[j] += sum[j + 1]; 8 9 return sum[0]; 10 }
基本动态规划题
代码:
1 int uniquePaths(int m, int n) { 2 vector<int> sum(n, 0); 3 4 sum[n - 1] = 1; 5 for (int i = m - 1; i >= 0; i--) 6 for (int j = n - 2; j >= 0; j--) 7 sum[j] += sum[j + 1]; 8 9 return sum[0]; 10 }