(最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087

http://acm.hdu.edu.cn/showproblem.php?pid=1087

Super Jumping! Jumping! Jumping!

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1087

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

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<algorithm>
using namespace std;

#define N 1000
#define oo 0x3f3f3f3f

int main()
{
    int n, a[N], sum[N];

    while(scanf("%d", &n), n)
    {
        int i, j;

        memset(a, 0, sizeof(a));
        memset(sum, 0, sizeof(sum));

        for(i=1; i<=n; i++)
            scanf("%d", &a[i]);

/**

我决定了要好好学 dp 这次写自然是要自己感悟的,自己想真的不容易,
尽管写过,尽管很简单,我也只是无奈,不好想

我又开了个数组 sum[], 里面记录的是从 1 开始到 i 最大的上升序列的和
既然 sum[i] 里记录的是最大的从 1 到 i 的值,那么每次比较 a[i] 和 a[j] 的大小
如果 a[i] 比 a[j] 大的话,就需要选 sum[i] 和 sum[j]+a[i] 的最大值

最后在 sum 中选个最大值就 OK 啦!!! 

**/

        for(i=1; i<=n; i++)
        {
            sum[i] = a[i];
            for(j=1; j<=i; j++)
            {
                if(a[i]>a[j])
                    sum[i] = max(sum[i], a[i]+sum[j]);
            }
        }

        int Max = -oo;

        for(i=1; i<=n; i++)
            Max = max(Max, sum[i]);

        printf("%d\n", Max);
    }
    return 0;
}

时间: 2024-11-03 21:56:35

(最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087的相关文章

[ACM] hdu 1087 Super Jumping! Jumping! Jumping! (动态规划)

Super Jumping! Jumping! Jumping! Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 6   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Nowada

[2016-03-27][HDU][1087][Super Jumping! Jumping! Jumping!]

时间:2016-03-27 15:51:40 星期日 题目编号:[2016-03-27][HDU][1087][Super Jumping! Jumping! Jumping!] 分析:dp[i]表示跳到第i个位置,能拿到的最多分,则dp[i] = max(dp[i] , dp[j] + v[i]) 能从j跳到i 遇到的问题:排序之和,a[1].v <= a[2].v 而不是 a[1].v < a[2].v 所以还是需要判断一下价值 #include <algorithm> #in

E - Super Jumping! Jumping! Jumping! HDU 1087 (基础动态规划)

E - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 1087 最大上升子序列和

题意:求最大上升子序列和 #include<iostream> using namespace std; int main() { int n,a[1001],b[1001],max; while(cin>>n&&n!=0) { for(int i=1;i<=n;i++) cin>>a[i]; b[1]=a[1]; for(i=2;i<=n;i++) { max=0; for(int j=1;j<i;j++) if(a[i]>a[

HDU 1069&amp;&amp;HDU 1087 (DP 最长序列之和)

H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Appoint description:  System Crawler  (2015-11-18) Description Nowadays, a kind of chess game called “Su

hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36986    Accepted Submission(s): 16885 Problem Description Nowadays, a kind of chess game called “Super Jumping!

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

HDU 1087 Super Jumping! Jumping! Jumping! 最大递增子序列

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32564    Accepted Submission(s): 14692 Problem Description Nowadays, a kind of chess game called “Super Jumping!