• HDOJ_ACM_Super Jumping! Jumping! Jumping!


    Problem Description
    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
     
    Code
    View Code
     1 #include <stdio.h>
     2 #define N 1000
     3 int f[N + 5];//mark number and don't modify
     4 int acc[N + 5];//accumulate the number and compare with each other 
     5 int main()
     6 {
     7     int i, j, n, max;
     8     while (scanf("%d", &n) != EOF && n)
     9     {
    10         //input
    11         for (i = 0; i < n; i++)
    12         {
    13             scanf("%d", &f[i]);
    14             acc[i] = f[i];
    15         }
    16         //find the longest substring
    17         max = f[0];
    18         for (i = 1; i < n; i++)
    19         {
    20             for (j = 0; j < i; j++)
    21             {
    22                 if (f[j] < f[i] && acc[j] + f[i] > acc[i])
    23                 {
    24                     acc[i] = acc[j] + f[i];
    25                     if (acc[i] > max)
    26                         max = acc[i];
    27                 }
    28             }
    29         }
    30         //print the result
    31         printf("%d\n", max);
    32     }
    33     return 0;
    34 }

    Key points

    After solved the before question about DP, I think this question is really a piece of cake.

    Using one array to mark the inputed number, and using the another array to mark the accumulating number.

    Each time comparing the sum of the present number and the previous accumulated number with the present accumulated number, you can confirm whether change the present accumulated number or not.

  • 相关阅读:
    jdk8 xp
    electron react
    electron install失败
    0511 Braft Editor和嵌套路由
    组播
    0427
    duilib自定义组件
    android 读写文件、列出根目录文件及新版本权限
    android Fragment使用RecyclerView
    Duilib 带xml的1
  • 原文地址:https://www.cnblogs.com/chuanlong/p/2775586.html
Copyright © 2020-2023  润新知