"The main topic"
There are n operations, each operation only success and failure, the success of the corresponding 1, the failure corresponds to the 0,n operation corresponds to 1 length of 01 strings of N. In this string continuous x 1 can contribute to the score of x^3, this x 1 cannot be included in the other continuous 1 (that is, a very long string of 1, see the sample explanation) now give N, as well as the success rate of each operation, please output the desired score, the output is rounded and retained 1 decimal places. "Idea" http://blog.csdn.net/popoqqq/article/details/49512533
If this 01 string makes sure, consider each new location, if this position is 0, the contribution is0, otherwise contribute to(X+1)3−x3=3x2+3x+ 1 , wherex length of the longest full 1 suffix before joining
Now this problem has become an expectation problem, so we just need to maintain a x expectation and < Span id= "Mathjax-element-376-frame" class= "Mathjax" > X2 The expectation of the . Note that the expectation of the square is not equal to the expected squared.
* Own supplement: about the nature of the probability operation: why l1[cur]= (l1[1-cur]+1) *a1? In fact, this should be the case: the probability of the current A1 can hit, the resulting expected suffix length (l1[1-cur]+1) *a1① currently has (1-A1) probability can not hit, the resulting expected suffix length 0* (1-a1) ②①+②→l1[cur]= (l1[1-cur) +1) *a1f is the general recursive addition, the current hit probability will not affect f[i-1], and the current probability of the impact of the factors only expected to increase the amount of
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <algorithm>6 using namespacestd;7 Doublel1[2],l2[2],f[2];8 intN;9 Ten intMain () One { Ascanf"%d",&n); - intCur=0; - for(intI=1; i<=n;i++,cur=1-cur) the { - DoubleA1; -scanf"%LF",&A1); -L1[cur]= (l1[1-cur]+1)*A1; +L2[cur]= (l2[1-cur]+2*l1[1-cur]+1)*A1; -f[cur]=f[1-cur]+ (3*l2[1-cur]+3*l1[1-cur]+1)*A1; + } Aprintf"%.1lf\n", f[1-cur]); at return 0; -}
"Probability DP" bzoj4318-osu!