zoukankan      html  css  js  c++  java
  • [UVALive 7143]Room Assignment(Dp)

    Description

    There are N guests checking in at the front desk of the hotel. 2K (0 ≤ 2K ≤ N) of them are twins.
    There are M rooms available. Each room has capacity ci which means how many guests it can hold.
    It happens that the total room capacity is N, i.e. c1 + c2 + . . . + cM = N.
    The hotel receptionist wonders how many different room assignments to accommodate all guests.
    Since the, receptionist cannot tell the two twins in any pair of twins apart, two room assignments are
    considered the same if one can be generated from the other by swapping the two twins in each of some
    number of pairs. For rooms with capacity greater than 1, it only matters which people are in the room;
    they are not considered to be in any particular order within the room.

    Solution

    题意:m个房间,每个房间有容量ci(总容量为n),n位客人,其中有k对双胞胎,双胞胎被看做同样的人,求方案数

    用f[i][j]表示分配到i个房子,还剩j对完整的双胞胎没有分配:

    f[i][j-k]+=f[i-1][j]*C(j,k)*C(sum-(j-k)*2-k,c[i]-k) sum表示剩下的还需分配的人

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #define Mod 1000000007
    #define N 100005
    typedef long long LL;
    using namespace std;
    int T,kase=0,n,m,K,c[20],p[20];
    LL f[20][110],fac[N],inv[N];
    void init()
    {
        fac[0]=1,inv[1]=1;
        for(int i=1;i<N;i++)
        fac[i]=(fac[i-1]*i)%Mod;
        for(int i=2;i<N;i++)
        inv[i]=(inv[Mod%i]*(Mod-Mod/i))%Mod;
        inv[0]=1;
        for(int i=1;i<N;i++)
        inv[i]=(inv[i-1]*inv[i])%Mod;
    }
    LL C(int m,int n)
    {
        if(m<n||m<0||n<0)return 0;
        return ((fac[m]*inv[n])%Mod*inv[m-n])%Mod;
    }
    int main()
    {
        init();
        scanf("%d",&T);
        while(T--)
        {
            ++kase;
            memset(f,0,sizeof(f));
            scanf("%d%d%d",&n,&m,&K);
            for(int i=1;i<=m;i++)
            {scanf("%d",&c[i]);p[i]=p[i-1]+c[i];}
            f[0][K]=1;
            for(int i=1;i<=m;i++)
            {
                int sum=p[m]-p[i-1];
                for(int j=0;j<=K;j++)
                {
                    for(int k=0;k<=j;k++)
                    {
                        f[i][j-k]+=(f[i-1][j]*C(j,k)%Mod)*C(sum-(j-k)*2-k,c[i]-k)%Mod;
                        f[i][j-k]%=Mod;
                    } 
                }
            }
            printf("Case #%d: %d
    ",kase,f[m][0]);
        }
        return 0;
    }
  • 相关阅读:
    Swift
    Swift
    POJ2029——Get Many Persimmon Trees
    windows-install-python-and-sphinx(*.rst file)
    【cocos2d-x】尝鲜 Cocos Code IDE(不断更新)
    mysql 删除重复数据sql声明
    开销是有益的:AppCan 至HTML5移动创新和创业精神和健康
    hibernate它5.many2one单向
    Insecure default in Elasticsearch enables remote code execution
    TestNg显示器(一个)-----监听器,类型和配置使用---另外META-INF详细解释
  • 原文地址:https://www.cnblogs.com/Zars19/p/6915665.html
Copyright © 2011-2022 走看看