• 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 }
  • 相关阅读:
    css3实现渐变进度条
    从实际项目出发,浅淡什么是设计空间
    消失的Controller
    深入理解Go系列一之指针变量
    48个国际音标简述
    【PyTorch】按照 steps 训练和保存模型
    用C/python手写redis客户端,兼容redis集群 (-MOVED和-ASK),快速搭建redis集群
    jsoncpp安装与使用 cmake安装 升级g++ gcc支持c++11
    【Android】解决Android Studio初次配置可能会出现的Unkown Host问题
    【数据结构】时间复杂度和空间复杂度计算
  • 原文地址:https://www.cnblogs.com/hsd-/p/5492987.html
Copyright © 2020-2023  润新知