zoukankan      html  css  js  c++  java
  • 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 } 
    keep moving...
  • 相关阅读:
    eclipse(java windows)
    Tomcat(Linux)
    Tomcat(Windows)
    MySql(Windows)
    Java EE API
    计算机网络-TCP三次握手理解
    onclick 和click 的区别
    js轮播图代码
    JS轮播图制作
    js动画原理
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2807942.html
Copyright © 2011-2022 走看看