首页 > 其他 > 详细

C - Functions again CodeForces - 789C (dp、思维)

时间:2020-04-11 18:57:07      阅读:53      评论:0      收藏:0      [点我收藏+]

C - Functions again

 CodeForces - 789C 

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long dp,maxx,dp2,maxx2,ans,a,b;
long long masx(long long a,long long b)
{
    if(a>=b) return a;
    else return b;
}
int main()
{
    int n;
    cin>>n>>a;
    int h=1;
    for(int i=0;i<n-1;++i)
    {
        scanf("%lld",&b);
        int f = abs( a - b ) * h;
        int f2 = abs( a - b ) * -h;
        dp = masx( dp+f, f);
        dp2 = masx( dp2+f2, f2);
        maxx = masx( dp, maxx);
        maxx2 = masx( dp2, maxx2);
        h*=-1;
        a=b;
    }
    ans = masx( maxx, maxx2 );
    printf( "%lld", ans );
}

 

C - Functions again CodeForces - 789C (dp、思维)

原文:https://www.cnblogs.com/Cnxz/p/12680510.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!