关闭

poj 2181 Jumping Cows

197人阅读 评论(0) 收藏 举报
分类:

直接上代码

#include<iostream>
#include<string.h>
#include<math.h>
#include<fstream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector> 
#define MAXSIZE 100
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
int P = 0; 
int dp[150010];
int dat[150010];
int incr[150010], decr[150010];
int main()
{
    //freopen("data_2181.txt","r",stdin);
    while(scanf("%d", &P) != EOF)
    {
        for (int i = 1; i <= P; i++)
        {
            scanf("%d", &dat[i]);
        }
        for (int i = 1; i <= P; i++)
        {
            incr[i] = max (incr[i - 1], decr[i - 1] + dat[i]);
            decr[i] = max (decr[i - 1], incr[i - 1] - dat[i]);
        }
        printf("%d\n", max (incr[P], decr[P]));
    }

    return 0;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场