题目
Description
有M个小孩到公园玩,门票是1元。其中N个小孩带的钱为1元,K个小孩带的钱为2元。售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱。注意:两个拿一元零钱的小孩,他们的位置互换,也算是一种新的排法。(M<=10)
Input
输入一行,M,N,K(其中M=N+K,M<=10).
Output
输出一行,总的排队方案。
Sample Input
4 2 2 Sample Output
8
代码块
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner cn =
new Scanner(System.
in);
int m = cn.nextInt();
int n = cn.nextInt();
int k = cn.nextInt();
if(n<k) System.
out.println(
0);
else {
int s1 =
1;
for(
int i =
1;i<=k;i++){
s1*=i;
}
int s2 =
1;
for(
int i =
1;i<=n;i++){
s2*=i;
}
int[][] dd =
new int[
20][
20];
for(
int i =
0;i<
20;i++){
for(
int j=
0;j<
20;j++){
dd[i][j]=
0;
}
}
dd[
1][
0]=
1;
dd[
1][
1]=
1;
for(
int i =
2;i<=n;i++){
for(
int j=
0;j<=i;j++){
for(
int e =
0;e<=j;e++){
dd[i][j]+=dd[i-
1][e];
}
}
}
System.
out.println(dd[n][k]*s2*s1);
}
cn.close();
}
}