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 }
    
    
  • 相关阅读:
    DatePicker 日期选择器 split-panels 数组的时候,清空这个费劲啊,最后走的后门
    英语音标总结
    前台发布地址动态获取 本机地址
    SecureCRT windows 登录 linux
    The History of the English language 英语语音的起源
    iview 部分表单验证
    iView 表单验证 如果prop字段和表单里的字段对不上,会触发校验,提示错误信息
    hdu4370 0 or 1
    即时通讯上手必备知识点
    不使用Math.random实现随机数。
  • 原文地址:https://www.cnblogs.com/shadervio/p/5766676.html
Copyright © 2011-2022 走看看