• 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;
    }
    蒹葭苍苍,白露为霜; 所谓伊人,在水一方。
  • 相关阅读:
    [ZJOI2010]基站选址
    [SDOI2008]Sue的小球
    访问计划
    奥义商店
    codeforces 809E Surprise me!
    codeforces 888G Xor-MST
    [HAOI2015]数字串拆分
    小奇分糖果
    小奇的花园
    BZOJ4711 小奇挖矿
  • 原文地址:https://www.cnblogs.com/huwt/p/9992521.html
Copyright © 2020-2023  润新知