OSU!
OSU!
期望dp
SCUACM2022集训前训练-动态规划 - Virtual Judge (vjudge.net)
-
若连续 x 次成功的贡献是 x,则第 \(i\) 次对答案的贡献为 \(1*p\)
-
但连续 x 次成功的贡献是 \(x^3\), 而期望只有线性性质,对于 \(x^3\) 不可累加
-
设第 \(i\) 个操作成功后,期望连续长度为 \(l1[i]\), 期望连续长度的平方为 \(l2[i]\)
- \(l1[i]=(l1[i-1]+1)*p\)
- \(l2[i]=(l2[i-1]+2*l1[i-1]+1)*p\)
-
设第 \(i\) 次成功后已经连了 \(x+1\) 次,那这一次对答案的贡献就是 \((x+1)^3-x^3=3x^2+3x+1\)
因此贡献为 \(3*l2[i]+3*l1[i]+1\)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
double dp[N], l1[N], l2[N], p;
int n;
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
scanf("%lf",&p);
dp[i] = (3 * l2[i-1] + 3 * l1[i-1] + 1) * p;
l1[i] = (l1[i-1] + 1) * p;
l2[i] = (l2[i-1] + l1[i-1] * 2 + 1) * p;
}
double ans = 0;
for(int i = 1; i <= n; i++)
ans += dp[i];
printf("%.1f\n",ans);
return 0;
}