概率DP
设 \(f(i,j)\) 表示前 \(i\) 项比赛除此人外得分为 \(j\) 的期望人数
有转移:
\(f(i,j)= \frac{1}{m-1} \sum_{k=j-m}^{j-1}f(i-1,k)\times[k\neq j-c_i]\)
很显然的前缀和
设 \(s_i = \sum_{j=1}^{i} f(i-1,j)\)
转移:
\(f(i,j)=\frac{1}{m-1} (s_{j-1}-s_{j-m-1}-f(i-1,j-c_i)\times[j-m\leq j-c_i \leq j-1])\)
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;
}
CF601C Kleofá? and the n-thlon 题解
原文:https://www.cnblogs.com/Ax-Dea/p/13951175.html