import java.util.*;
import java.math.BigInteger;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param m int整型
* @param n int整型
* @return int整型
*/
public int uniquePaths (int m, int n) {
// write code here
if(m==0||n==0){
return 1; }
int bu1=m-1;
int bu2=n-1;
BigInteger result=new BigInteger("1");
result=getjie(bu1+bu2).divide(getjie(bu1)).divide(getjie(bu2));
//共走m+n-2步,其中向右的步数为m-1,计算m-1在这个总步数总共有多少走法,就需要运用组合数
// 公式C(m,n)=m!/n!/(m-n)!;
return result.intValue();
}public BigInteger getjie(int n){//因为阶乘值过大甚至可能导致long溢出,可以用BigInteger;
BigInteger b=new BigInteger("1");
BigInteger i=new BigInteger("1");
String str=n+"";
BigInteger num=new BigInteger(str);
while(i.compareTo(num)<=0){
b=b.multiply(i);
i=i.add(BigInteger.ONE);
}
return b;
}
}