1.问题描述:
A robot is located at the top-left corner of m X n grid.
The robot can only move either down or right an any point in time.The robot is try to reach the bottom-right corner of the grid.
How many possible unique paths are there?
2.java实现
package dynamic;
/*Unique Paths
A robot is located at the top-left corner of m X n grid
*/
public class UniquePaths {
public static int uniquePaths(int m,int n) {
int[][] f = new int[m][n];
int i, j;
for (i = 0; i < m; i++) {//row: top to bottom
for (j = 0; j < n; j++) {//column: left to right
if (i == 0 || j == 0) {
f[i][j] = 1;
} else {
f[i][j] = f[i - 1][j] + f[i][j - 1];
}
}
}
return f[m - 1][n - 1];
}
public static void main (String [] args)
{
System.out.println(uniquePaths(7,3));
}
}