本文共 927 字,大约阅读时间需要 3 分钟。
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?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)); }}
转载地址:http://fyhdi.baihongyu.com/