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\n",Max);
37     }
38     return 0;
39 }
时间: 2024-08-04 10:21:17

hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)的相关文章

[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

HDU 1087 Super Jumping! Jumping! Jumping! 简单DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意:N个数字组成的一条路,每个数字是一个节点顺序连接,起点在第一个数之前,终点在第N个数之后.现让你选择一条路从起点跳到终点,只能往前且跳到比当前点大的那个点,可以认为终点是最大的,可以从起点直接跳到终点但是路的值就是0了,每条路的值为所经过的数字节点的值的和,问你值最大为多少. 解题思路:决策:在当前点i往i~N哪个点跳,反过来当前点i+1可以从1~i哪个点跳过来,那么a[i+1] >

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

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 t

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

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

HDU 1087 Super Jumping! Jumping! Jumping! (DP)

C - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, a

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

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

HDU 1087 Super Jumping! Jumping! Jumping!【DP】

解题思路:题目的大意是给出一列数,求这列数里面最长递增数列的和 dp[i]表示到达地点i的最大值,那么是如何达到i的呢,则我们可以考虑没有限制条件时候的跳跃,即可以从第1,2,3,---,i-1个地点跳跃到i, 而题目限定了,跳到的那个点的数要比开始跳的那个点的数大 所以,状态转移方程式为 for(i=1;i<=n;i++)   for(j=0;j<i;j++) if(a[j]>a[i])   dp[i]=max(dp[j]+a[i],dp[i]);//找出到达地点i的最大值 反思:本来