zoukankan      html  css  js  c++  java
  • HDU 1087——Super Jumping! Jumping! Jumping!(动态DP)

    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

    解题思路:就是求最长上升子序列的和(LIS)

    代码:
     1 #include<iostream>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int n;
     7     while(scanf("%d",&n)!=EOF&&n)
     8     {
     9         int dp[1010]={0};//dp是最大值,b是当前数
    10         int b[1010]={0};
    11         for(int i=0;i<n;i++)
    12         {
    13             int temp=0;
    14             int max=-1;
    15             scanf("%d",&temp);
    16             b[i]=temp;
    17             bool find=false;
    18             for(int j=0;j<i;j++)
    19             {
    20                 if((b[j]<temp)&&(dp[j]+temp>max))
    21                 {
    22                     max=dp[j]+temp;
    23                     find=true;
    24                 }
    25             }
    26             if(find)
    27                 dp[i]=max;
    28             else 
    29                 dp[i]=b[i];
    30         }
    31         int out=-1;
    32         for(int i=0;i<n;i++)
    33         {
    34             if(out<dp[i]) out=dp[i];
    35         }
    36         printf("%d
    ",out);
    37     }
    38     return 0;
    39 }
    
    
  • 相关阅读:
    mybatis公用代码抽取到单独的mapper.xml文件
    mysql与oracle常用函数及数据类型对比00持续补充
    人民币在岸 离岸 中间价的含义与关系
    mysql hang and srv_error_monitor_thread using 100% cpu(已解决)
    long和BigDecimal引发的管理思考
    mybatis 3的TypeHandler深入解析(及null值的处理)
    mysql 5.7.17发布
    rabbitmq connection/channel/consumer/queue的数量关系详细分析
    rabbitMQ publish丢包分析
    INFO: task java:27465 blocked for more than 120 seconds不一定是cache太大的问题
  • 原文地址:https://www.cnblogs.com/shadervio/p/5766676.html
Copyright © 2011-2022 走看看