Super Jumping! Jumping! Jumping!(hdu 1087 LIS*)

Super Jumping! Jumping! Jumping!

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

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

 求最大上升子序列的和 状态转移方程很好想,和 求LIS基本一样,

    : dp[i]=max(dp[i],dp[j]+a[i])  (a[j]<a[i])

  但一开始需要对dp进行初始化,wa了两发,dp[i]=a[i],这是dp[i]的最小值

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 #define max(a,b) a>b?a:b
 6 int dp[1005];
 7 int a[1005];
 8 int main()
 9 {
10     int n;
11     int i,j;
12     long long sum;
13     freopen("in.txt","r",stdin);
14     while(scanf("%d",&n)&&n)
15     {
16         memset(dp,0,sizeof(dp));
17         for(i=0;i<n;i++)
18         {
19             scanf("%d",&a[i]);
20             dp[i]=a[i];
21         }
22         sum=0;
23         for(i=0;i<n;i++)
24         {
25             for(j=0;j<i;j++)
26             {
27                 if(a[j]<a[i])
28                     dp[i]=max(dp[i],dp[j]+a[i]);
29             }
30             sum=max(sum,dp[i]);
31         }
32         printf("%d\n",sum);
33     }
34     return 0;
35 }
时间: 2024-08-10 17:22:07

Super Jumping! Jumping! Jumping!(hdu 1087 LIS*)的相关文章

Constructing Roads In JGShining&#39;s Kingdom(HDU 1025 LIS nlogn方法)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21002    Accepted Submission(s): 5935 Problem Description JGShining's kingdom consists of 2n(n is no mor

HDU 1025 Constructing Roads In JGShining&#39;s Kingdom(二维LIS)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23467    Accepted Submission(s): 6710 Problem Description JGShining's kingdom consists of 2n(n is no mo

UVA10599 - Robots(II)(变形的LIS)

题意:一个机器人在n * m的网格里面捡垃圾,机器人只能向右或向下走,求出能捡到的垃圾数量的最大值,有多少条路径可以达到最大值,以及输出其中一条路径. 思路:按照题意可以看出,因为机器人只能向右和向下走,所以纵坐标就不重要的,而横坐标是递增的.当将所有拥有垃圾的格子经过计算得到它的一维值(唯一的),得到一组的数组.那就可以转化为求最长上升子序列.但这个LIS的条件是mod(m)要大于前一个.计算数量时,当d[i] = d[j] + 1时,就相当于以i为结束时的最长上升子序列比以j结束时的最长上升

BZOJ 1264 基因匹配Match(LCS转化LIS)

题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1264 题意:给出两个数列,每个数列的长度为5n,其中1-n每个数字各出现5次.求两个数列的最长公共子列. 思 路:首先找出每个数字在第二个数列中出现的位置,对于第一个数列构造出一个新的数列,每个数用这个数在第二个数列中出现的5个位置代替.这样求最长上升子 列.注意的是,在求到每个数(这里指原第一个数列中的每个数)为止的LIS时,替换后的5个数字要先求大的..不清楚的看代码. int a

UVA 11368 &amp; POJ 3636 &amp; HDU 1677 Nested Dolls(贪心 + 二分LIS)

A - Nested Dolls Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Dilworth is the world's most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls

UVa 10534 波浪子序列(快速求LIS)

https://vjudge.net/problem/UVA-10534 题意:给定一个长度为n的整数序列,求一个最长子序列(不一定连续),使得该序列的长度为2k+1,前k+1个数严格递增,后k+1个数严格递减. 思路: 先正着求一遍LIS,再反着求一遍LIS. 当然求法是得采用O(nlogn)的求法,这个网上有很多解释,我就不多介绍了. 最后的话枚举一遍就可以了,详见代码. 1 #include<iostream> 2 #include<algorithm> 3 #include

hdu 1087(LIS变形)

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

HDU 1087 (LIS)

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

HDU 1257 最少拦截系统(Dilworth定理+LIS)

最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35053    Accepted Submission(s): 13880 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的