zoukankan      html  css  js  c++  java
  • HDU

    题意:从起点依次跳跃带有数字的点直到终点,要求跳跃点上的数字严格递增,问跳跃点的最大数字和。

    分析:

    1、若之前的点比该点数字小,则可进行状态转移,dp[i] = max(dp[i], dp[j] + a[i]);

    2、dp[i]---截止到i,跳跃的最大数字和。

    3、由于不确定最终是哪个点直接跳往终点可保证数字和最大,因此,扫一遍,ans = max(ans, dp[i]);

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define lowbit(x) (x & (-x))
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 1000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int a[MAXN];
    int dp[MAXN];
    int main(){
        int N;
        while(scanf("%d", &N) == 1){
            if(N == 0) return 0;
            memset(dp, 0, sizeof dp);
            for(int i = 1; i <= N; ++i){
                scanf("%d", &a[i]);
            }
            for(int i = 1; i <= N; ++i){
                dp[i] = a[i];
                for(int j = 1; j <= i - 1; ++j){
                    if(a[j] < a[i]){
                        dp[i] = max(dp[i], dp[j] + a[i]);
                    }
                }
            }
            int ans = 0;
            for(int i = 1; i <= N; ++i){
                ans = max(ans, dp[i]);
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Regular Expression Matching
    Palindrome Number
    String to Integer (atoi)
    Reverse Integer
    ZigZag Conversion
    Longest Palindromic Substring
    Add Two Numbers
    git 操作原理
    ES6学习之路2----变量的解构赋值
    ES6学习之路1----变量的声明
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7345930.html
Copyright © 2011-2022 走看看