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

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

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 21836    Accepted Submission(s): 9562

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

代码如下:

#include <cstdio>
#define N 1017
int main()
{
	int n;
	int a[N], dp[N];
	int i, j;
	int max;
	while(~scanf("%d",&n) && n)
	{
		for(i = 0; i < n; i++)
		{
			scanf("%d",&a[i]);
		}
		dp[0] = max = a[0];
		for(i = 1; i < n; i++)
		{
			dp[i] = a[i];
			for(j = 0; j < i; j++)
			{
				if(a[i] > a[j])
				{
					if(dp[j]+a[i] > dp[i])
					{
						dp[i] = dp[j]+a[i];
					}
				}
			}
			if(dp[i] > max)
				max = dp[i];
		}
		printf("%d\n",max);
	}
	return 0;
}
时间: 2024-10-10 17:06:23

hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)的相关文章

[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

[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

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 1025 dp 最长上升子序列

1 //Accepted 4372 KB 140 ms 2 //dp 最长上升子序列 nlogn 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 500005; 8 int dp[imax_n]; 9 int d[imax_n]; 10 int a[imax_n]; 11 int n; 12 int len

HDU 1160 FatMouse&#39;s Speed (动规+最长递减子序列)

FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9174    Accepted Submission(s): 4061 Special Judge Problem Description FatMouse believes that the fatter a mouse is, the faster

HDU 3998 Sequence(经典问题,最长上升子序列)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3998 解题报告:求一个数列的最长上升子序列,并求像这样长的不相交的子序列最多有多少个. 我用的是最简单的方法,就是每次求最长上升子序列,然后每次将求得的子序列从数列里面删掉,然后再对剩下的数列求最长上升子序列,如果求得的子序列的长度比第一次求得的长度小的话,就退出.不过我这题卡了很久,原因就是因为用这种方法求的过程中,用到了很多变量,但是没有注意每一步求最长上升子序列的时候都要进行初始化,哎. Vi

POJ 2250 Compromise (DP,最长公共子序列)

Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6440 Accepted: 2882 Special Judge Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfille

poj1836——dp,最长上升子序列(lis)

poj1836——dp,最长上升子序列(lis) Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13767   Accepted: 4450 Description In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight

codeforces340D - Bubble Sort Graph dp + 最长上升子序列

题意:给你长为n的序列 ,每个节点都和在它前面且值比他大的点产生一条边,问你一个最大 两两点没有边的集合的 集合元素有多少 解题思路:想了半天才发现是最长上升子序列.. 解题代码: 1 // File Name: 340d.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月03日 星期日 12时31分24秒 4 5 #include<vector> 6 #include<list> 7 #include<map>

UVA 10131 Is Bigger Smarter?(DP最长上升子序列)

Description Question 1: Is Bigger Smarter? The Problem Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible in