fzu 1715 Ball and Box n个不同的求放到m个不同的盒子中方法的个数

1715 Ball and Box

Accept: 120    Submit: 288
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

CDGG has r different boxes and n different balls.He want to put the n balls into the r boxes,and it is not allow to left empty box.How many ways can CDGG put the n balls into the r boxes?

 Input

The input consists of several test cases. For each case,the only line contains two integer n and r,indicates the number of balls and the number of boxes.(0<=n,r<=10)

 Output

For each case,output a line contain a integer,indicates the answer.

 Sample Input

3 2

 Sample Output

6
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//第二类斯特林数
void Stirling_2(__int64 a[][25],int n)
{
    //注意:不能在这里写memset(a..);这样不能对main函数中的a数组初始化
    //memset(a,0,sizeof(a));
    a[1][1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            a[i][j]=j*a[i-1][j]+a[i-1][j-1];
        }
    }
}
int main()
{
    
    __int64 a[25][25],fac[25]={0,1};
    memset(a,0,sizeof(a));
    Stirling_2(a,20);
    for(int i=2;i<=20;i++) fac[i]=fac[i-1]*i;
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        __int64 cnt=a[n][m]*fac[m];//important
        printf("%I64d/n",cnt);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值