在XxY的方格中绘证,以左上角格子為起點撵割,右下角格子為終點,每次只能向下走或者向右走跑杭,請問一共有多少種不同的走法
給定兩個正整數(shù)int x,int y铆帽,請返回走法數(shù)目。保證x+y小于等于12德谅。
測試樣例:
2,2
返回:2
class Robot {
public:
int factorial(int n)
{
if(n == 0) return 1;
return n*factorial(n-1);
}
int countWays(int x, int y) {
// write code here
if(x <= 1 && y <= 1) return 0;
return factorial(x+y-2) / factorial(x-1) / factorial(y-1);
}
};