P1365 WJMZBMR打osu! / Easy ( 期望dp

#include 
using namespace std;
using VI = vector;
double a[200010];
double len[200010];
double len2[200010];
double dp[500010];
int n;
string s;

int main(){
    cin>>n;
    cin>>s;
    s = " " + s;
    len[0] = 0;
    for(int i = 1 ; i <= n ; i++){
        double p = 0;
        if(s[i] == 'o') p = 1;
        else if ( s[i] == 'x') p = 0;
        else p = 0.5;

        len[i] = (len[i-1] + 1) * p;
        dp[i] = dp[i-1] + (2 * len[i-1] + 1) * p;




    }

    printf("%.4lf" , dp[n]);


}



你可能感兴趣的:(dp,算法)