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;
    }
    蒹葭苍苍,白露为霜; 所谓伊人,在水一方。
  • 相关阅读:
    今天整理了一下博客文章
    让我们猜猜明天凌晨一点NASA会有什么重大消息公布?
    微软2010 PDC Party郑州社区行
    记一次Shiro反序列化到远程桌面
    从公有云到渗透进内网漫游
    华为云CTF cloud非预期解之k8s渗透实战
    记一次任意文件下载到getshell
    记一次失败的实战渗透
    Subversion for Windows 安装配置
    使用Fiddler2录制HTTP操作脚本
  • 原文地址:https://www.cnblogs.com/huwt/p/9992521.html
Copyright © 2011-2022 走看看