zoukankan      html  css  js  c++  java
  • HDU

    Super Jumping! Jumping! Jumping!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 40650    Accepted Submission(s): 18805


    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
     
    题解:
      该题的意思是求一个递增最大和序列
      给出n,在给出n个数,然后从左往右跳,规则是必须跳向比自己大的数,只能往右跳,中间可以隔着数跳
      问这些数加起来,最大和是多少
      下面是自己举的例子和演算过程
      
      arr[]:存放n个数    dp[][]:存放和
      在dp[i][i]中存放在跳到arr[i]这个数时,之前的最大和是多少
      判断arr[i]这一步的最大和时,先查找之前比arr[i]小的数,若存在arr[j]
      即dp[i][j] = dp[j][j] + arr[i];
      然后再将dp[i][]这一行找到的最大值放在dp[i][i]处,以便后续使用
      
      
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 typedef long long LL;
     8 LL dp[1010][1010];
     9 
    10 int main()
    11 {
    12     int n;
    13     LL arr[1010];
    14     while(scanf("%d",&n) && n) {
    15 
    16         for(int i = 0 ; i < n ; i++)
    17             scanf("%lld",&arr[i]);
    18         LL ans;
    19         for(int i = 0; i < n ; i++){
    20             ans = arr[i];
    21             for(int j = 0; j < i; j++) {
    22                 if(arr[i] > arr[j]){
    23                     dp[i][j] = dp[j][j] + arr[i];
    24                     ans = ans < dp[i][j] ? dp[i][j] : ans;
    25                 }
    26                 else
    27                     dp[i][j] = arr[i];
    28             }
    29             dp[i][i] = ans;
    30         }
    31         for(int i = 0 ; i < n ;i++)
    32             ans = ans < dp[i][i] ? dp[i][i] : ans;
    33         printf("%lld
    ",ans);
    34     }
    35     return 0;
    36 }
      
  • 相关阅读:
    js常用函数(不断添加中。。。)
    【转】linux常用命令全集
    【转】VC++消息钩子编程
    beyond compare ftp 文件夹同步
    【转】notepad++ 应用学习 -- 列模式,十六进制模式
    网页嵌入视频播放器
    java中 正则表达式的使用
    【转】正则表达式30分钟入门教程
    【转】深入研究java.lang.Runtime类
    js 中map的几种实现方式
  • 原文地址:https://www.cnblogs.com/creativepower/p/7357081.html
Copyright © 2011-2022 走看看