https://www.zybuluo.com/ysner/note/1300315 Problem surface
There is a total of \ (n\) operations, each operation only success and failure of the points, the success of the corresponding \ (1\), the failure of the corresponding \ (0\),\ (n\) operation corresponds to \ (1\) A \ (01\) string of length \ (n\) .
In this string continuous \ (x\) ( 1\) can contribute to the score of \ (x^3\) , this \ (x\) \ (1\) cannot be other consecutive \ ( 1\) is included.
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 place.
How can I ask for this thing?
Set \ (x1_i\) indicates the expected length of the \ (1\) string ending with \ (i\) . (Table Increment)
\ (x2_i\) represents the square of the desired length of the \ (1\) string ending with \ (i\) . (Table Increment)
\ (x3_i\) indicates the expected score of the string to \ (i\) . (Cumulative answer)
\ (x1[i]= (x1[i-1]+1) *p\)
The transfer of \ (x_2\) can apply a full square formula:
\ (x2[i]= (x2[i-1]+2*x1[i-1]+1) *p\)
The transfer of F3 is the result of probability multiplication:
\ (x3[i]=x3[i-1]* (1-p) + (x3[i-1]+3*x2[i-1]+3*x1[i-1]+1) *p\)
#include<iostream>#include<cmath>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#define ll long long#define re register#define il inline#define pb(a) push_back(a)#define fp(i,a,b) for(re int i=a;i<=b;i++)#define fq(i,a,b) for(re int i=a;i>=b;i--)using namespace std;const int N=1e5+100;int n;double x1[N],x2[N],x3[N],p;il int gi(){ re int x=0,t=1; re char ch=getchar(); while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘)) ch=getchar(); if(ch==‘-‘) t=-1,ch=getchar(); while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-48,ch=getchar(); return x*t;}int main(){ n=gi(); fp(i,1,n) { scanf("%lf",&p); x1[i]=(x1[i-1]+1)*p; x2[i]=(x2[i-1]+2*x1[i-1]+1)*p; x3[i]=x3[i-1]+(3*x2[i-1]+3*x1[i-1]+1)*p; } printf("%.1f\n",x3[n]); return 0;}
luogu1654 osu!