The topics are as follows:
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 is there?
Above is a 3 x 7 grid. How many possible unique paths is there?
Note: m and N would be is at most 100.
This problem is very simple, it is to describe the dynamic programming algorithm. Read the code to understand.
1 intUniquepaths (intMintN) {2 int*A;3A= (int*)malloc(sizeof(int) *m*n);4 intb;5 for(a=m-1, b=0; b<n;b++){6a[a*n+b]=1;7 }8 for(b=n-1, a=0; a<m;a++){9a[a*n+b]=1;Ten } One for(a=m-2; a>=0; a--){ A for(b=n-2; b>=0; b--){ -a[a*n+b]=a[(A +1) *n+b]+a[a*n+b+1]; - } the } - returna[0]; -}
A similar question minimum Path sum can be solved by this method.
Leetcode Unique Paths