zoukankan      html  css  js  c++  java
  • hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

    Super Jumping! Jumping! Jumping!

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


    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
     
    题目大意:求解最大递增子序列和,这里要特别注意一点:这个题目不要求是连续的最大递增子序列。但是一定要注意是递增的!!
     
    题目思路:dp数组表示是包含当前这个数的最大递增子序列和。dp[i]表示的是前i个并且包含第i个的最大递增子序列和!给个数据:3 1 4 显然dp[1]=3,dp[2]=1表示两个数的最大值。因为分两种情况讨论,如果第二个数大于第一个数,就加上,即dp[2]=dp[1]+num[2];如果不大,dp[2]=num[2];dp[3]=7表示三个数的最大值。首先比较num[3]和num[1],如果num[3]>num[1],dp[3]=7先存下来,如果num[3]>num[2],dp[3]=5依旧存下来;还有一种如果num[3]比前两个值都小,dp[3]=num[3];最后在存下来的dp[3]中找到一个最大的!呼呼~终于解释差不多了,小伙伴们也屡一下思路吧0.0
     
     
    详见代码。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int num[1010],dp[1010];
     8 
     9 int main ()
    10 {
    11     int n,Max;
    12     while (~scanf("%d",&n))
    13     {
    14         if (n==0)
    15             break;
    16         Max=0;
    17         memset(dp,0,sizeof(dp));
    18         for (int i=0;i<n;i++)
    19         {
    20             scanf("%d",&num[i]);
    21         }
    22         dp[0]=num[0];
    23         for (int i=1;i<n;i++)
    24         {
    25             for (int j=0;j<i;j++)
    26             {
    27                 if (num[i]>num[j])
    28                 dp[i]=max(dp[i],dp[j]+num[i]);
    29             }
    30             dp[i]=max(dp[i],num[i]);
    31         }
    32         for (int i=0;i<n;i++)
    33         {
    34             Max=max(Max,dp[i]);
    35         }
    36         printf ("%d
    ",Max);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    Smart TV Alliance SDK2.0简介
    为字符串数组排序。每个字符串可能包含数字,字母,汉字
    为数组添加自定义函数,可完成执行[1,2,3,4,5].twoself() 输出新数组[1,2,3,4,5,1,2,3,4,5]
    vueJS 解决VSCode 中 报错"You may use special comments to disable some warnings. Use // eslint-disable-next-line to ignore the next line. Use /* eslint-disable */ to ignore all warnings in a file."
    table-一列细分为多列(合并单元格)
    利用闲暇时间帮朋友做一个小页面
    保护url时效性和安全性的一种解决方案
    highcharts-3d.js实现饼状图
    eclipse 遇到的问题及解决思路
    git初步使用
  • 原文地址:https://www.cnblogs.com/qq-star/p/4293962.html
Copyright © 2011-2022 走看看