G - The Galactic Olympics Gym - 101147G -DP(第二类斯特林数)

  • G - The Galactic Olympics

     Gym - 101147G 
  • 题意:
  • Foki is in a big problem. How can he decide whom of his children is going to participate in which game, at the same time his children must participate in all the games and every one of his children get to participate in at least one game?
  • Note that in a certain arrangement, each one of Foki's children can participate in multiple games in the Olympics, but each game must be arranged to exactly one player.
  • Your job is to help Foki and answer his question: in how many way can he arrange his children to the games in Venus Olympics while satisfying the previous two conditions.
  • 所有的孩子必须参加游戏,至少参加一个,但是每一个游戏只能由一个人参加,确定一下参加的方案数
  • 思路:
  • 第二类斯特林数:将n个不同的球放入m个无差别的盒子中,要求盒子非空,有几种方案?
  • 假设要把J个元素分成 i 个集合则分析如下:
  • (1)如果 j-1 个元素构成了i-1个集合,那么第 j 个元素单独构成一个集合。方案数=j*dp[i-1][j-1].
  • (2)如果j-1个元素已经构成了 i 个集合,将第 j 个元素插入到任意一个集合。方案数=j*dp[i-1][j].
  • 所以总情况为j*(dp[i-1][j-1]+dp[i-1][j]),特别处理:(i==j)dp[i][j]=dp[i-1][j-1]*i。
  • 几种变形:
  • 第二类Stirling数主要是用于解决组合数学中的几类放球模型。主要是针对于球之前有区别的放球模型:
  • (1)n个不同的球,放入m个无区别的盒子,不允许盒子为空。
  • 方案数:这个跟第二类Stirling数的定义一致。
  • (2)n个不同的球,放入m个有区别的盒子,不允许盒子为空。
  • 方案数:因盒子有区别,乘上盒子的排列即可。
  • (3)n个不同的球,放入m个无区别的盒子,允许盒子为空。
  • 方案数:枚举非空盒的数目便可。
  • (4)n个不同的球,放入m个有区别的盒子,允许盒子为空。
  • ①方案数:同样可以枚举非空盒的数目,注意到盒子有区别,乘上一个排列系数。
  • ②既然允许盒子为空,且盒子间有区别,那么对于每个球有m中选择,每个球相互独立。
  • #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ldq 1000000007
    #define maxn 1332
    ll dp[maxn][maxn],n,k,t;
    int main()
    {
        freopen("galactic.in","r",stdin);
        dp[0][0]=1;
        for(int i=1; i<=1000; i++)
            for(int j=1; j<=i; j++)
            {
                if(j==1)dp[i][1]=1;
                else if(i==j)dp[i][j]=dp[i-1][j-1]*i%ldq;
                else dp[i][j]=j*(dp[i-1][j-1]+dp[i-1][j])%ldq;
            }
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&k);
            if(k>n)printf("0\n");
            else
                printf("%d\n",dp[n][k]);
        }
        return 0;
    }

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值