zoukankan      html  css  js  c++  java
  • 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.

    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
    #include <stdio.h>
    #include <string.h>
    
    #define MAX 1005
    
    int main()
    {
        int n;
        int num[MAX]; //存入输入数据
        //存入从以第一个数作为结束到以最后一个数作为结束时的最大和
        int maxSum[MAX];  
        int maxTemp;
        int max;
        int i,j;
        while (~scanf("%d",&n))
        {
          if (n==0)
            break;
          for (i=1; i<=n; i++)
            scanf("%d",&num[i]);
          memset(maxSum,0,sizeof(maxSum));  //先将maxSum置零
          maxSum[1] = num[1];   //第一个数的最大状态即为第一个数
          for (i=2; i<=n; i++)
          {
            maxTemp = 0;
            for (j=1; j<i; j++)
              //在题目条件下选出最大状态
              if (num[j]<num[i]&&maxSum[j]>maxTemp)
                maxTemp = maxSum[j];
            maxSum[i] = num[i]+maxTemp;
          }
          max = maxSum[1];
          for (i=2; i<=n; i++)
            if (max<maxSum[i])
              max = maxSum[i];
          printf("%d
    ",max);
        }
        return 0;
    }
    蒹葭苍苍,白露为霜; 所谓伊人,在水一方。
  • 相关阅读:
    全文索引--自定义chinese_lexer词典
    转 Oracle全文检索http://docs.oracle.com/cd/E11882_01/text.112/e24436/toc.htm
    .net安装windows服务配置文件config
    如何制作windows服务安装包
    spring jpa @Query中使用in
    sql trunc()的使用
    [转]轻松解决oracle11g 空表不能exp导出的问题
    HTTP协议状态码详解(HTTP Status Code)
    解决Could not commit JPA transaction RollbackException: Transaction marked as rollbackOnly
    解析Java对象的equals()和hashCode()的使用
  • 原文地址:https://www.cnblogs.com/huwt/p/9992521.html
Copyright © 2011-2022 走看看