m人参加n场比赛,已知某一人各比赛的名次,求它的期望总名次(各比赛名次相加的和的排名)

显然期望dp
对于其它m-1人,令Ei,s表示第i场比赛得分为s的期望


CF 601C(Kleofáš and the n-thlon-期望dp)_#define

然后前缀和乱搞

#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
#define
double E[MAXN][MAXN*MAXM];
int n,m,a[MAXN];
int main()
{
freopen("CF601C.in","r",stdin);
// freopen(".out","w",stdout);
n=read(),m=read();
For(i,n) a[i]=read();
if (m==1) {
cout<<"1.0000000000000000\n";
return 0;
}
MEM(E)
Rep(j,m+1) E[0][j]=1.0;
For(i,n) {
Fork(s,i,i*m) {
E[i][s]=E[i-1][s-1] - ((s-m-1>=0)?E[i-1][s-m-1]:0) ;
if (s>=a[i]) E[i][s]-=E[i-1][s-a[i]]-((s-a[i]-1>=0)?E[i-1][s-a[i]-1]:0);
E[i][s]/=m-1;
}
For(s,i*m+m) {
E[i][s]+=E[i][s-1];
}
}
int s1=0;
For(i,n) s1+=a[i];
cout<<setprecision(10)<<setiosflags(ios::fixed)<<(m-1)*E[n][s1-1]+1<<endl;
return 0;
}