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;
    }
    蒹葭苍苍,白露为霜; 所谓伊人,在水一方。
  • 相关阅读:
    Delphi三层开发小技巧:TClientDataSet的Delta妙用
    Delphi ADOQuery的速度优化
    delphi ADOQUery中错误解决方法"无法为更新定位行。一些值可能已在最后...
    ClientDataSet中修改,删除,添加数据和Delta属性
    学习 SQL 语句
    Delphi处理数据网格DBGrid的编辑框 获取还没有提交到数据集的字段文本
    移动前端头部标签(HTML5 head meta)
    最全面的前端开发指南
    解决jQuery.live在mobile safari(iphone / ipad / ipod)绑定失败的问题
    jQuery滑动选取数值范围插件
  • 原文地址:https://www.cnblogs.com/huwt/p/9992521.html
Copyright © 2011-2022 走看看