不同路径

 

题源:leetcode

链接:https://leetcode-cn.com/problems/unique-paths/

 

一道动态规划题,维护一个m*n的数组即可

 1 class Solution {
 2 public:
 3     int uniquePaths(int m, int n) {
 4         vector<vector<int>> f(m, vector<int>(n));
 5         for (int i = 0; i < m; ++i) {
 6             f[i][0] = 1;
 7         }
 8         for (int j = 0; j < n; ++j) {
 9             f[0][j] = 1;
10         }
11         for (int i = 1; i < m; ++i) {
12             for (int j = 1; j < n; ++j) {
13                 f[i][j] = f[i - 1][j] + f[i][j - 1];
14             }
15         }
16         return f[m - 1][n - 1];
17     }
18 };

 

不同路径

上一篇:git命令和基本用法整理


下一篇:Kettle安装配置