nssl1296-猫咪的进化【dp】
生活随笔
收集整理的這篇文章主要介紹了
nssl1296-猫咪的进化【dp】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
正題
題目大意
nnn次,每次有3種選擇:
解題思路
定義fi,0/1/2f_{i,0/1/2}fi,0/1/2?表示第iii次為休息/叫一聲/叫兩聲時的最大價值。
fi,0f_{i,0}fi,0?可以由前面任何狀態轉移過來。
而fi?1,1/2f_{i-1,1/2}fi?1,1/2?時就只能由fi?1,0/1f_{i-1,0/1}fi?1,0/1?轉移過來
codecodecode
#include<cstdio> #include<algorithm> #define l ((i+1)&1) using namespace std; int n; double v,f[2][3]; double read() {double d=0,ff=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') ff=-1;ch=getchar();}while (ch>='0'&&ch<='9')d=d*10+(double)(ch-48),ch=getchar();if (ch!='.') return d*ff;double cnt=10;ch=getchar();while (ch>='0'&&ch<='9')d=d+((double)(ch-48)/cnt),ch=getchar(),cnt*=10.0;return d*ff; } int main() {//freopen("data.in","r",stdin);scanf("%d",&n);for(int i=1;i<=n;i++){v=read();f[i&1][0]=max(f[l][0],max(f[l][1],f[l][2]));f[i&1][1]=max(f[l][0],f[l][1])+v;f[i&1][2]=max(f[l][0],f[l][1])+v*v;}printf("%.4lf",max(max(f[n&1][0],f[n&1][1]),f[n&1][2])); }總結
以上是生活随笔為你收集整理的nssl1296-猫咪的进化【dp】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P1768-天路【负环,SPFA,01分
- 下一篇: 国际老人节是几月几日 你知道吗