1. 程式人生 > >HDU 2713: Jumping Cows

HDU 2713: Jumping Cows

cow geeks author ace [0 pro pid space pin


///@ref geeksforgeeks
///@author Sycamore
///@date 9/11/2017
///@link http://acm.hdu.edu.cn/showproblem.php?pid=2713
#include<bits/stdc++.h>
using namespace std;
int m[150001][2];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int P,s;
	while (cin >> P)
	{
 
		m[0][0] = m[0][1] = 0;
		for (int i = 1; i <= P; i++)
		{
			cin >>
s; m[i][0] = max(m[i-1][0], m[i - 1][1] + s); m[i][1] = max(m[i-1][1], m[i - 1][0] - s); } cout << max(m[P][0], m[P][1])<<‘\n‘; } return 0; }

HDU 2713: Jumping Cows