zoukankan      html  css  js  c++  java
  • HDU 1087 最大上升子序列的和

    Super Jumping! Jumping! Jumping!

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


    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[i] 代表 以a[i]为结尾的 上升子序列的最大和
            当增加第i个数a[i]时 只需要在 j= 1~i-1中寻找在 a[j]<a[i]的情况下的 dp[j]的最大值maxn  
            然后更新 dp[i]=maxn+a[i]  存储 dp[i]的最大值 输出
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 using namespace std;
     5 int n;
     6 int a[1005];
     7 int ans[1005];
     8 int exm;
     9 int main()
    10 {
    11     while(scanf("%d",&n)!=EOF)
    12 {
    13     if(n==0)
    14     break;
    15     for(int i=1;i<=n;i++)
    16     {
    17      scanf("%d",&a[i]);
    18      ans[i]=a[i];
    19     }
    20     int maxlen=-1;
    21     for(int i=2;i<=n;i++)
    22    {
    23      int maxn=0;
    24      for(int j=1;j<i;j++)
    25      {
    26          if(a[j]<a[i]&&maxn<ans[j])
    27          {
    28              maxn=ans[j];
    29          }
    30      }
    31      ans[i]=maxn+a[i];
    32       if(ans[i]>maxlen)
    33       {
    34         maxlen=ans[i];
    35         exm=i;
    36       }
    37     }
    38      cout<<maxlen<<endl;
    39 }
    40     return 0;
    41 }
  • 相关阅读:
    准备工作:安装Arduino驱动(Windows)
    关于osEye的URL设计
    Debian 6.0下安装Memcached
    准备工作:购买Arduino
    debian6.0安装后中文字体显示不正常的解决办法
    取消UL和OL符号以及padding和margin后恢复默认值的CSS
    linux中reboot、shutdown、halt等命令详细讲解
    IIS6中应用程序池和Web园,解决Session丢失问题
    [z]C# winForm 程序调用 Java WebService
    [z]HTMLTextBox
  • 原文地址:https://www.cnblogs.com/hsd-/p/5492987.html
Copyright © 2011-2022 走看看