标签:+= max scanf class lang com printf clu lan
想出状态转移的难度很小
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2020;
double eps=1e-5;
double Aimee[maxn];
double p[maxn];
double f[2][maxn];
int n,m,k;
double p1,p2,p3,p4;
int main(){
while(scanf("%d%d%d%lf%lf%lf%lf",&n,&m,&k,&p1,&p2,&p3,&p4)!=EOF){
if(p4<eps){
printf("0.00000\n");
continue;
}
double p21=p2/(1-p1);
double p41=p4/(1-p1);
double p31=p3/(1-p1);
p[0]=1.0;
for(int i=1;i<=n;++i) p[i]=p21*p[i-1];
f[1][1]=p41/(1-p21);
Aimee[1]=p41;
for(int i=2;i<=n;++i){
int Ai=i&1;
for(int j=2;j<=k;++j)
Aimee[j]=p31*f[Ai^1][j-1]+p41;
for(int j=k+1;j<=i;++j){
Aimee[j]=p31*f[Ai^1][j-1];
}
double tmp=Aimee[1]*p[i-1];
for(int j=2;j<=k;j++)
tmp+=Aimee[j]*p[i-j];
for(int j=k+1;j<=i;++j)
tmp+=Aimee[j]*p[i-j];
f[Ai][i]=tmp/(1-p[i]);
f[Ai][1]=p21*f[Ai][i]+Aimee[1];
for(int j=2;j<i;++j) f[Ai][j]=p21*f[Ai][j-1]+Aimee[j];
}
printf("%.5lf\n",f[n&1][m]);
}
return 0;
}
标签:+= max scanf class lang com printf clu lan
原文地址:https://www.cnblogs.com/For-Miku/p/14360545.html