zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    IoC模式
    开发流程与模式
    YbSoftwareFactory
    简单的FTP文件安全识别方案
    C# 通过探测邮件服务器进行Email地址有效性检验
    YbRapidSolution for WinForm 插件生成项目总体架构介绍
    lucene.net已经从孵化器毕业
    XSql 源码开放
    TCP 套接字函数和入门级TCP编程
    C#中泛型学习笔记
  • 原文地址:https://www.cnblogs.com/sineatos/p/3522171.html
Copyright © 2011-2022 走看看