zoukankan      html  css  js  c++  java
  • ACM Super Jumping! Jumping! Jumping!

    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. 

    InputInput 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. 
    OutputFor 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
     1 /*
     2     Name:  Super Jumping! Jumping! Jumping! 
     3     Copyright: 
     4     Author: 
     5     Date: 11/08/17 13:26
     6     Description: 访问棋子,下一步要访问的棋子要比目前的棋子的标记数要大,且不能返回,求最大数
     7                 用dp算法思想,用dp数组记录到目前的棋子的最优走法,直至最后一个棋子。 
     8 */
     9 
    10 #include<iostream>
    11 #include<cstring>
    12 #include<algorithm>
    13 using namespace std;
    14 const int NUM = 1005;
    15 int chessman[NUM],dp[NUM]; 
    16 int main()
    17 {
    18     int N,ans;
    19     while(cin>>N && N)
    20     {
    21         for(int i = 0; i < N; i++)
    22             cin>>chessman[i];
    23         
    24         dp[0] = chessman[0];
    25         ans = dp[0];
    26         for(int i = 1; i < N; i++)
    27         {
    28             dp[i] = chessman[i];
    29             for(int j = 0; j < i; j++)
    30             {
    31                 if(chessman[j] < chessman[i] && chessman[i] + dp[j] > dp[i])  /*dp思想*/ 
    32                     dp[i] = chessman[i] + dp[j];
    33                 
    34                 ans = max(ans,dp[i]);
    35             }
    36         }
    37         cout<<ans<<endl;
    38         
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    Mysql常用语句
    Java基础知识总结
    ExtJS4.2学习(三)——入门基础
    ExtJS4.2学习(二)——入门基础
    ExtJS 4.2学习(一)——环境搭建
    大三下半学期“饭店餐饮系统”项目笔记
    GUI练习——列出指定目录内容
    Collections之sort的两个方法(自然排序和自定义比较器排序)
    Java集合总结
    访问数据库
  • 原文地址:https://www.cnblogs.com/jj81/p/7267825.html
Copyright © 2011-2022 走看看