日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[UVALive 7143]Room Assignment(Dp)

發布時間:2025/5/22 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [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\n",kase,f[m][0]);}return 0; }

?

轉載于:https://www.cnblogs.com/Zars19/p/6915665.html

總結

以上是生活随笔為你收集整理的[UVALive 7143]Room Assignment(Dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。