题解:
这种
x
3
x^3
x3的题很容易想到用
x
2
x^2
x2,
x
1
x^1
x1这两个状态来转移过来。
因为我们发现
(
x
+
1
)
3
(x+1)^3
(x+1)3拆开可以用这三个东西来表示。
于是定义状态
d
p
[
i
]
[
3
]
dp[i][3]
dp[i][3]
第二维的1表示长链尾部连续1的
x
1
x^1
x1
2表示长链尾部连续1的
x
2
x^2
x2
3表示答案
详细转移见代码 核心思想就是三次方和平方的分解
代码:
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}
db dp[N][5];
db p[N];
int main(){
//freopen("1.txt","r",stdin);
//ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf",&p[i]);
}
for(int i=1;i<=n;i++){
dp[i][1]=(dp[i-1][1]+1)*p[i];
dp[i][2]=(dp[i-1][2]+dp[i-1][1]*2.0+1)*p[i];
dp[i][3]=dp[i-1][3]+(dp[i-1][2]*3.0+dp[i-1][1]*3.0+1)*p[i];
}
printf("%.1f\n",(ll)((dp[n][3]*10.0+0.5))/10.0);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}