题解 | #走方格的方案数#
走方格的方案数
http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(getNum(m,n));
}
}
public static int getNum(int row,int column){
if(row==0 || column==0){
return 1;
}else{
//因为每次只有向下和向右,两种选择
return getNum(row-1,column)+getNum(row,column-1);
}
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(getNum(m,n));
}
}
public static int getNum(int row,int column){
if(row==0 || column==0){
return 1;
}else{
//因为每次只有向下和向右,两种选择
return getNum(row-1,column)+getNum(row,column-1);
}
}
}