[LintCode]unique paths

http://www.lintcode.com/zh-cn/problem/unique-paths/

递推公式:f[m][n] = f[m-1][n]+f[m][n-1]

可采用DP或者记忆化的递归实现。

下面是递归实现的代码:

 1 #include <cstring>
 2 class Solution {
 3 public:
 4     /**
 5      * @param n, m: positive integer (1 <= n ,m <= 100)
 6      * @return an integer
 7      */
 8     int f[101][101];
 9     Solution() { memset(f, 0, sizeof(f)); }
10     int uniquePaths(int m, int n) {
11         // wirte your code here
12         if(m==1||n==1) return f[m][n] = 1;
13         return f[m][n]?f[m][n]:f[m][n] = uniquePaths(m-1, n)+uniquePaths(m, n-1);
14     }
15 };
原文地址:https://www.cnblogs.com/pczhou/p/4651725.html