标签:
class Solution { public: /** * @param n, m: positive integer (1 <= n ,m <= 100) * @return an integer */ int uniquePaths(int m, int n) { // wirte your code here if(m == 0 || n == 0) return 0; if( m == 1) return 1; if( n == 1) return 1; /* return uniquePaths(m-1,n) + uniquePaths(m,n-1); */ // int f[m+1][n+1] = {0}; //int** f = (int**)new int[(m+1) * (n+1) * sizeof(int)]; int f[101][101] = {0}; for(int j = 1; j <= n; j++) { f[1][j] = 1; } for(int i = 1; i <= m; i++) { f[i][1] = 1; } for(int i = 2; i <= m; i++) { for(int j = 2; j <= n; j++) { f[i][j] = f[i-1][j] + f[i][j-1]; } } return f[m][n]; } };
class Solution { public: /** * @param n, m: positive integer (1 <= n ,m <= 100) * @return an integer */ int uniquePaths(int m, int n) { // wirte your code here if(m == 0 || n == 0) return 0; if( m == 1) return 1; if( n == 1) return 1; /* return uniquePaths(m-1,n) + uniquePaths(m,n-1); */ // int f[m+1][n+1] = {0}; //int** f = (int**)new int[(m+1) * (n+1) * sizeof(int)]; int f[101][101] = {0}; for(int j = 1; j <= n; j++) { f[1][j] = 1; } for(int i = 1; i <= m; i++) { f[i][1] = 1; } for(int i = 2; i <= m; i++) { for(int j = 2; j <= n; j++) { f[i][j] = f[i-1][j] + f[i][j-1]; } } return f[m][n]; } };
标签:
原文地址:http://www.cnblogs.com/cis2000/p/4805694.html