• HDU


    先上题目:

    Super Jumping! Jumping! Jumping!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 18956    Accepted Submission(s): 8136


    Problem Description
    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.



    The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
    Your task is to output the maximum value according to the given chessmen list.
     
    Input
    Input contains multiple test cases. Each test case is described in a line as follow:
    N value_1 value_2 …value_N 
    It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
    A test case starting with 0 terminates the input and this test case is not to be processed.
     
    Output
    For each case, print the maximum according to rules, and one line one case.
     
    Sample Input
    3 1 3 2
    4 1 2 3 4
    4 3 3 2 1
    0
     
    Sample Output
    4
    10
    3
     
      这一题说白了就是最长上升序列,以前一直不敢做dp= =,现在才开始做,还wa了两三次,觉得有点忏悔= =。这一题我写的代码时间复杂度为O(n^2),不过在网上看到有人说有复杂度是O(nlogn)的,好像是加了个二分查找进去= =。
      状态转移方程: dp[i]=max{dp[j] , j<i && a[j]<a[i]} + a[i];
     
    上代码:
    #include <cstdio>
    #include <cstring>
    #define MAX 1001
    using namespace std;
    
    long long n,a[MAX],dp[MAX];
    
    
    
    int main()
    {
        long long maxm;
        while(scanf("%I64d",&n),n){
            for(int i=0;i<n;i++){
                scanf("%I64d",&a[i]);
            }
            memset(dp,0,sizeof(dp));
            maxm=0;
            for(int i=0;i<n;i++){
                dp[i]=a[i];
                for(int j=i-1;j>=0;j--){
                    if(a[j]<a[i] && dp[j]+a[i]>dp[i]){
                            dp[i]=dp[j]+a[i];
                    }
                }
                maxm = dp[i] > maxm ? dp[i] : maxm;
            }
            printf("%I64d
    ",maxm);
        }
        return 0;
    }
    1087
  • 相关阅读:
    2020_java面试
    Centos7.2 安装docker、mysql和redis
    【源码讲解】Spring事务是如何应用到你的业务场景中的?
    奇葩说今晚聊前任|扒一扒你的前任企业邮箱
    一封一封邮件发送太累?个人邮箱快速群发解决烦恼
    企业邮箱客户端收发服务器如何设置?
    163VIP邮箱怎么设置邮件签名?如何群发邮件?
    企业版邮箱哪个适合学校邮箱?企业邮箱托管服务
    企业版邮箱购买哪个?公司邮箱如何申请?
    公司邮箱登录入口是?公司邮箱申请入口在?
  • 原文地址:https://www.cnblogs.com/sineatos/p/3522171.html
Copyright © 2020-2023  润新知