HDU2713
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
keep moving...