Problem 15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?

本文探讨了一个20x20网格中从左上角到右下角的不同路径数量问题,在不回头的情况下,通过组合数学原理计算可能的路径总数。文章提供了一种简单的方法来计算这一数值:利用排列组合公式 (m+n)!/(m!n!) 来求解。
 
题目:

Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 2020 grid?


	/**
	 * 
	 * 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();
	}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值