题意:有n个人,m间浴室,每间浴室有a[I]个浴缸,每个人要洗澡的话都要排队,假如一群人进入同一个浴室,他们总倾向于使得最长的队伍最短,现在问所有队伍最长的期望。
思路:概率dp。用状态dp[I][j][k]表示还剩I间浴室,还剩j个人,之前最长队伍的长度为k的期望最长队伍长度。
那么可以得到状态转移方程
dp[I][j][k] = sigma(dp[I-1][j-c][max(k, (c+a[i]-1)/a[i])] * (I-1)^j / I^j * C(j, c))
其中c是枚举当前去第j间浴室的人数。
#include <bits/stdc++.h>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MAXN = 55;
//const int MOD = 1e9+7;
//const int INF = 0x3f3f3f3f;
int n, m;
int a[MAXN];
double dp[MAXN][MAXN][MAXN];
double C[MAXN][MAXN];
void init() {
C[0][0] = 1.0;
for (int i = 1; i <= 50; i++) {
C[i][0] = 1.0;
for (int j = 1; j <= i; j++)
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
int main()
{
//freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &m);
init();
for (int i = 1; i <= m; i++)
scanf("%d", &a[i]);
for (int i = 0; i <= n; i++)
dp[0][0][i] = i;
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
for (int c = 0; c <= j; c++) {
int maxq = max(k, (c+a[i]-1)/a[i]);
dp[i][j][k] += dp[i-1][j-c][maxq] * pow(i-1, j-c) / pow(i, j) * C[j][c];
}
}
}
}
printf("%.12f\n", dp[m][n][0]);
return 0;
}