HDU2713

View Code
 1 /*
 2 DP
 3 n个数,奇数步相加,偶数步相减
 4 */
 5 #include<stdio.h>
 6 #include<stdlib.h>
 7 #include<string.h>
 8 #include<iostream>
 9 #include<algorithm>
10 #include<queue>
11 #include<map>
12 #include<math.h>
13 using namespace std;
14 const int maxn = 150005;
15 const int inf = 0x7fffffff;
16 int dp[ maxn ][ 2 ];
17 int a[ maxn ];
18 int main(){
19     int n;
20     while( scanf("%d",&n)!=EOF ){
21         for( int i=1;i<=n;i++ ) scanf("%d",&a[ i ]);
22         memset( dp,0,sizeof(dp) );
23         for( int i=1;i<=n;i++ ){
24                 dp[ i ][ 0 ]=max( dp[ i-1 ][ 0 ],dp[ i-1 ][ 1 ]-a[ i ] );//
25                 dp[ i ][ 1 ]=max( dp[ i-1 ][ 0 ]+a[ i ],dp[ i-1 ][ 1 ] );//奇数步 是 偶数步+a[i] 和 前i-1奇数步 中的最大值
26         }
27         printf("%d\n",max( dp[ n ][ 0 ],dp[ n ][ 1 ]));
28     }
29     return 0;
30 } 

 

转载于:https://www.cnblogs.com/xxx0624/archive/2012/12/07/2807942.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值