【BZOJ2134】单位错选(数学期望,动态规划)
题面
题解
单独考虑相邻的两道题目的概率就好了
没了呀。。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
inline int read()
{
RG int x=0,t=1;RG char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
double ans;
int a[10000002],n,A,B,C;
int main()
{
n=read();A=read();B=read();C=read();a[1]=read();
for(int i=2;i<=n;++i)a[i]=(1ll*a[i-1]*A%100000001+B)%100000001;
for(int i=1;i<=n;++i)a[i]=a[i]%C+1;a[n+1]=a[1];
for(int i=1;i<=n;++i)ans+=1.0/max(a[i],a[i+1]);
printf("%.3lf\n",ans);
return 0;
}