CF788A Functions again dp

Posted guangheli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF788A Functions again dp相关的知识,希望对你有一定的参考价值。

求一个最长子段和就完了,可以出T1?

code: 

#include <bits/stdc++.h>
#define N 100006 
#define ll long long 
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std; 
ll a[N],A[N],B[N],f[N],g[N];           
int main() 

    ll mx=0;  
    int i,j,n; 
    // setIO("input"); 
    scanf("%d",&n);   
    for(i=1;i<=n;++i) scanf("%lld",&a[i]); 
    for(i=1;i<n;++i) 
    
        if(i%2==1) A[i]=abs(a[i]-a[i+1]), B[i]=-A[i];  
        else A[i]=-abs(a[i]-a[i+1]), B[i]=-A[i];      
    
    f[1]=A[1], g[1]=B[1];       
    mx=max(A[1], B[1]);  
    for(i=2;i<n;++i) 
    
        f[i]=max(f[i-1],0*1ll)+A[i];   
        g[i]=max(g[i-1],0*1ll)+B[i];   
        mx=max(mx, f[i]); 
        mx=max(mx, g[i]); 
    
    printf("%lld\n",mx); 
    return 0; 

  

以上是关于CF788A Functions again dp的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 789 C Functions again DP

codeforces C. Functions again

CF1221D Make The Fence Great Again

Codeforces Round #407 (Div. 2) C Functions again(最大子序列和)

CF578D. LCS Again

LightOJ 1038 Race To 1 Again(概率DP)