1054: 【排队买票】

xiaoxiao2021-02-27  565

题目

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++){ //求出k个人的排列数 s1*=i; } int s2 = 1; for(int i =1;i<=n;i++){ //求出n个人的排列数 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++){ //由i个1元小朋友和j个2元小朋友组成的队伍排法 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(); } }
转载请注明原文地址: https://www.6miu.com/read-887.html

最新回复(0)