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

  • 相关阅读:
    P4555 [国家集训队]最长双回文串(回文树)
    【洛谷 P3805】 【模板】manacher算法
    【洛谷 P2485】 [SDOI2011]计算器 (BSGS)
    【洛谷 P3846】 [TJOI2007]可爱的质数 (BSGS)
    【洛谷 P1712】 [NOI2016]区间 (线段树+尺取)
    【洛谷 P1251】 餐巾计划问题 (费用流)
    【洛谷 P1337】[JSOI2004]平衡点 / 吊打XXX (模拟退火)
    【POJ 1719】 Shooting Contest (二分图匹配)
    【洛谷 P1631】 序列合并 (堆)
    【洛谷 P2515】 [HAOI2010]软件安装 (缩点+树形背包)
  • 原文地址:https://www.cnblogs.com/chuanlong/p/2775586.html
Copyright © 2011-2022 走看看