思路:
这个题目就是求c(m+n-2,n-1)。。也是组合数学里面非降路径的概念
import java.math.BigInteger;
public class Solution {
public int uniquePaths(int m, int n) {
BigInteger result=new BigInteger("0");
BigInteger up=new BigInteger("1");
BigInteger down=new BigInteger("1");
for(int i=m;i<m+n-1;i++)
{
up=up.multiply(new BigInteger(Integer.toString(i)));
}
for(int i=1;i<=n-1;i++)
{
down=down.multiply(new BigInteger(Integer.toString(i)));
}
result=up.divide(down);
return Integer.valueOf(result.toString());
}
}
本文介绍了一种求解机器人从起点到终点行走路径的方法,使用组合数学中的非降路径概念,通过Java实现了一个计算不同网格大小下机器人可行路径数量的算法。
588

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



