题目描述
把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。
输入
每个用例包含二个整数M和N。0<=m<=10,1<=n<=10。<=n<=10<=m<=10
样例输入
7 3
样例输出
8
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
int n2 = sc.nextInt();
System.out.println(getNum(n1,n2));
}
private static int getNum(int apple, int plane) {
// TODO Auto-generated method stub
if((apple<0)||(apple>10)||(plane<1)||(plane>10)){
return -1;
}
else if(apple==1||plane==1||apple==0){
return 1;
}
else if(apple<plane){
return getNum(apple, plane-1);
}
else{
return getNum(apple-plane, plane)+getNum(apple, plane-1);
}
}
}