| 题目: Starting in the top left corner of a 2
How many routes are there through a 20 |
/**
*
* 1. from 0,0 to m,n, it needs m+n steps.
*
* 2. u need m steps to forward right.
*
* 3. so, it's a simple permutation (m+n)!/(m!n!)
*
* 4. It just like that u have 20 same red balls and 20 same blue balls.
* how many permutation there are.
*
* @param m
* @param n
* @return
*/
public static long findRoutes(int m, int n) {
BigDecimal bd = BigDecimal.ONE;
for (int i = n + 1; i <= m + n; i++) {
bd = bd.multiply(new BigDecimal(i));
}
for (int i = 1; i <= m; i++) {
bd = bd.divide(new BigDecimal(i));
}
System.out.println("----" + bd);
return bd.longValue();
}
|
Problem 15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
最新推荐文章于 2018-10-18 12:20:17 发布
本文探讨了一个20x20网格中从左上角到右下角的不同路径数量问题,在不回头的情况下,通过组合数学原理计算可能的路径总数。文章提供了一种简单的方法来计算这一数值:利用排列组合公式 (m+n)!/(m!n!) 来求解。
6012

被折叠的 条评论
为什么被折叠?



