A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 class Solution { 2 public: 3 int uniquePaths(int m, int n) { 4 /* if(n==1) 5 return 1; 6 int ans=0; 7 vector<int> jlist(n-1,1); 8 for(int i=1;i<m;i++) 9 { 10 for(int j=0;j<n-1;j++) 11 { 12 if(j==0) 13 jlist[j]++; 14 else 15 jlist[j]+=jlist[j-1]; 16 } 17 } 18 return jlist[n-2];*/ 19 int ans=0; 20 vector<int> jlist(n,1); 21 for(int i=1;i<m;i++) 22 { 23 for(int j=1;j<n;j++) 24 jlist[j]+=jlist[j-1]; 25 } 26 return jlist[n-1]; 27 } 28 };