标签:online 就是 c++ log 否则 solution 分数 blog ons
所以我们可以得到转移方程:
\(ch[i]==o\) 时,\(f[i]=f[i-1]+1 ~~~~~~~~~~~ dp[i]=dp[i-1]+f[i-1]*2+1\)
\(ch[i]==x\) 时,\(f[i]=0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dp[i]=dp[i-1]\)
\(ch[i]==?\) 时,\(f[i]=(f[i-1]+1)/2 ~~~~~dp[i]=dp[i-1]+(f[i-1]*2+1)/2\)
//it is coded by ning_mew on 7.22
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+7;
double ans=0,dp[maxn],f[maxn];
int n;
char ch[maxn];
int main(){
scanf("%d",&n); scanf("%s",ch);
for(int i=1;i<=n;i++){
if(ch[i-1]=='x'){f[i]=0;dp[i]=dp[i-1];continue;}
if(ch[i-1]=='o'){f[i]=f[i-1]+1;dp[i]=dp[i-1]+f[i-1]*2+1;continue;}
if(ch[i-1]=='?'){f[i]=0.5*f[i-1]+0.5;dp[i]=dp[i-1]+(f[i-1]*2+1)/2;continue;}
}printf("%0.4f\n",dp[n]);return 0;
}
博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会场场比赛暴0!!!
【题解】 bzoj3450 JoyOI1952 Easy (期望dp)
标签:online 就是 c++ log 否则 solution 分数 blog ons
原文地址:https://www.cnblogs.com/Ning-Mew/p/9351389.html