• 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;
    }
    

      

  • 相关阅读:
    Http接口安全设计
    RTMP服务器搭建(nginx+rtmp)
    OSI七层协议详解
    TCP协议的3次握手与4次挥手过程【深度详解】
    new和delete的深层次剖析(C++)
    大小端模式详解
    MP4文件格式分析及分割实现(附源码)
    使用HBuilder将H5的项目打包成手机可安装的webapp程序(.apk)
    Centos7 解决odoo10打印条形码显示方框乱码的问题
    linux 中运行Django项目
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7345930.html
Copyright © 2020-2023  润新知