概率DP(应该是小于等于蓝题的难度
设 (f(i,j)) 表示前 (i) 项比赛除此人外得分为 (j) 的期望人数
有转移:
(f(i,j)= frac{1}{m-1} sum_{k=j-m}^{j-1}f(i-1,k) imes[k eq j-c_i])
很显然的前缀和
设 (s_k = sum_{j=1}^{k} f(i-1,j))
转移:
(f(i,j)=frac{1}{m-1} (s_{j-1}-s_{j-m-1}-f(i-1,j-c_i) imes[j-mleq j-c_i leq j-1]))
答案即为 (1+sum_{i=1}^{c-1}f(n,i))
Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 110,M = (int)1e3+7;
int n,m,c[N],C;
double f[N][N*M],s[N*M],g[N*M];
int main() {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) scanf("%d",&c[i]),C += c[i];
for(int i=1;i<=m;++i) if(i!=c[1]) f[1][i] = 1.0;
for(int i=2;i<=n;++i) {
for(int j=1;j<=i*m;++j) s[j] = s[j-1]+f[i-1][j];
for(int j=i;j<=i*m;++j)
if(j<=m+1) g[j] = s[j-1] - f[i-1][j-c[i]] * (1<=j-c[i]);
else g[j] = s[j-1] - s[j-m-1] - f[i-1][j-c[i]] * (j-m<=j-c[i]);
for(int j=i;j<=i*m;++j) f[i][j] = g[j]/(m-1);
}
double ans = 0.0;
for(int i=1;i<=C-1;++i) ans += f[n][i];
printf("%.16lf",ans+1.0);
return 0;
}