zoukankan      html  css  js  c++  java
  • Super Jumping! Jumping! Jumping!杭电1087

    Description


    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]时,只需在j=1~(i-1)中寻找在a[j]<a[i]的情况下的dp[j]的最大值max然后更新dp[i]=max+a[i]  ,记录最大值输出。
     
    代码实现:
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 using namespace std;
     7 int main()
     8 {
     9     int n,a[1005],dp[1005],i,j,k,ans,max;
    10     while(cin>>n&&n)
    11     {
    12         memset(dp,0,sizeof(dp));
    13         for(i=0;i<n;i++)
    14         cin>>a[i];
    15         for(i=0;i<n;i++)
    16         {
    17             max=0;
    18             for(j=0;j<i;j++)
    19             {
    20                 if(a[j]<a[i])
    21                 {
    22                     max=max>dp[j]?max:dp[j];
    23                 }
    24             }
    25             dp[i]=max+a[i];
    26         }
    27         ans=0;
    28         for(i=0;i<n;i++)
    29         ans=ans>dp[i]?ans:dp[i];
    30         cout<<ans<<endl;
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    drf请求生命周期
    正向代理和反向代理
    cbv源码分析
    Python搭建调用本地dll的Windows服务(浏览器可以访问,附测试dll64位和32位文件)
    Python实现聊天机器人接口封装部署
    Python实现机器人语音聊天
    Python爬虫下载美女图片(不同网站不同方法)
    微信小程序-点餐系统
    Win10系统Python3.8的升级与安装
    Python破解Wifi密码思路
  • 原文地址:https://www.cnblogs.com/WHLdbk/p/5699879.html
Copyright © 2011-2022 走看看