题目:
题意:
在每个单位时间内,有三种选择,求如何组合能使得获得的进化量
分析:
随便打打 d p dp dp,但毕竟是野鸡 O J OJ OJ上的题,以至于那么小的 n n n也要开个快读
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline double read()
{
double x=0,t=0;int s=0,f=1;char c=getchar();
for (;!isdigit(c);c=getchar()) {if (c=='-') f=-1;if (c=='.') goto readt;}
for (;isdigit(c)&&c!='.';c=getchar()) x=x*10+c-'0';
readt:for (;c=='.';c=getchar());
for (;isdigit(c);c=getchar()) t=t*10+c-'0',++s;
return (x+t/pow(10,s))*f;
}
double w[800005],f[800005][2];
int main()
{
int n=read();
for(int i=1;i<=n;i++) w[i+1]=read();
for(int i=2;i<=n;i++) f[i][0]=f[i][1]=-2147483640/3;
for(int i=2;i<=n+1;i++)
{
f[i][0]=max(f[i-1][0],max(f[i-1][0]+w[i],f[i-2][1]+w[i]));
f[i][1]=max(f[i-1][0]+w[i]*w[i],max(f[i-2][1]+w[i]*w[i],f[i-1][1]));
}
printf("%.4lf",max(f[n+1][0],f[n+1][1]));
return 0;
}