码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1087 最大递增子序列

时间:2019-05-24 01:07:30      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:poi   图片   rod   value   little   his   i++   print   rip   

Super Jumping! Jumping! Jumping!

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


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

 

 

 

【题意】

  这个游戏可以由两个人或两个人以上玩。它由一个棋盘和一些棋子组成,所有的棋子都用一个正整数或“开始”或“结束”来标记。玩家从起点开始,最终必须跳到终点。在跳跃的过程中,玩家将访问路径中的棋子,但是每个人都必须从一个棋子跳到另一个更大的棋子(您可以假设起点是最小的,终点是最大的)。所有的玩家都不能倒退。一次跳跃可以从一个棋子跳到下一个棋子,也可以跨越许多棋子,甚至可以直接从起点到终点。当然在这种情况下你得到的是0。当且仅当一名运动员能根据他的跳跃方案得到一个更大的分数时,他就是赢家。注意,你的分数来自于你跳跃路径上棋子的价值总和。

  我们需要根据给定的棋子列表输出最大值。

 

【代码】

#include<bits/stdc++.h>
using namespace std;
int sum[1001],a[1001];
int main(){
    int i,n,mmax=0,maxa=0;
    while(cin>>n && n){
        memset(a,0,sizeof(a));
        for(i=1; i<=n; i++){
            cin>>a[i];
        }
        for(i=1; i<=n; i++){
            mmax = 0;
            for(int j=1; j<i; j++)
                if(a[j] < a[i])
                    mmax = max(sum[j],mmax);
            sum[i] = mmax + a[i];
            maxa = max(maxa,sum[i]);
        }
        cout<<maxa<<endl;
        maxa = 0;
    }
    return 0;
}

 

HDU 1087 最大递增子序列

标签:poi   图片   rod   value   little   his   i++   print   rip   

原文地址:https://www.cnblogs.com/fangxiaoqi/p/10915452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!