做题记录 Luogu P1654

P1654 OSU! - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

递推,分别维护一次和二次的和。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
int n;
double p[N], x1[N], x2[N], f[N];
signed main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%lf", &p[i]);
	}
	for(int i = 1; i <= n; i++)
	{
		x1[i] = (x1[i - 1] + 1) * p[i];
		x2[i] = (x2[i - 1] + 2 * x1[i - 1] + 1) * p[i];
		f[i] = f[i - 1] + (3 * (x2[i - 1] + x1[i - 1]) + 1) * p[i];
	}
	printf("%0.1lf", f[n]);
	return 0;
}
上一篇:做题记录 Luogu CF559C


下一篇:做题记录 Luogu P1365