HDU1087 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): 32561    Accepted Submission(s): 14689

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

 1 #include <iostream>
 2 #include <string.h>
 3 using namespace std;
 4 int dp[1111];
 5 int N,temp;
 6 int a[1111];
 7 //dp[j] = max{dp[i]}+temp;
 8 int main()
 9 {
10     while(cin>>N,N){
11         for(int i=0;i<N;i++)
12             cin>>a[i];
13         memset(dp,0,sizeof(dp));
14         dp[0]=a[0];
15
16         for(int i=1;i<N;i++){
17             temp=0;
18             for(int j=0;j<i;j++){
19                  if(a[i]>a[j]){
20                     temp = max(temp,dp[j]);
21
22                  }
23             }
24             dp[i] = a[i] + temp;
25         }
26         temp=-1;
27         for(int i=0;i<N;i++){
28             if(temp<dp[i])
29                 temp=dp[i];
30         }
31         cout<<temp<<endl;
32     }
33     return 0;
34 }
时间: 2024-10-12 13:55:08

HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段的相关文章

得到最长连续递增序列

今天作死,看到别人发出来的笔试题就开干了,这tmd还理解错题目了,连续递增序列理解成上一个=下一个-1了. 这是我的成果,撸了4个多小时的: public class Test12 { public static void main(String[] args){ /** * 需求:找出最长的连续递增序列 * 步骤: * 1.找出所有连续序列可能结果,删除不是连续递增序列的,加入集合 * 2.集合排序,取第一个 * * 方式2: * 0.默认len为数组长度 * 1.找出数组中长度为len的序列

任意区间的最长连续递增子序列,最大连续子序列和

hdu3308 给n个数,有m个操作 U a b 表示将第a个数改成b Q a b 表示询问区间[a,b]的最长连续递增子序列. 区间询问问题且带修改,一般是用线段树来解决 那么要维护 Llen[rt], Lval[rt][2] 表示rt所对应的区间[l,r] 以l开头的最长连续递增子序列的长度, Lval[rt][0]表示子序列的最左边的值,Lval[rt][1]表示子序列最右边的值 Rlen[rt],Rval[rt][2]  表示rt所对应的区间[l,r]以r结尾的最长连续递增子序列的长度,

连续递增子串最长长度的数学期望

参考 [1]: longest consecutive subsequence of a random permutation     第一个帖子:         Theorem: The expected length of the longest increasing block in a random permutation of {1,2,…,n} is r0(n)+O(1) as n→∞, where r0(n) is the smallest positive integer su

3.分治法研究-搜索数组中的最长连续递增子集

//分治算法研究 搜索数组中的最长连续递增子集var cc=consolefunction find_max_crossing_lenarray(A,low,mid,high){    var max_left=mid,max_right=mid    var left_sum=1    var sum=0    for(var i=mid;i>low;i--){        sum=A[i]-A[i-1]        if(sum==1){            left_sum++   

最长连续递增子序列(部分有序)

题目:(1,9,2,5,7,3,4,6,8,0,)中最长的递增子序列为(3,4,6,8). 代码: public class 最长递增子序列 { public static void main(String[] args) { int []arr = {1,0,2,5,7,3,4,6,8,9,1,2}; getLargestLen(arr); } private static void getLargestLen(int[] arr) { int begin=0; // 最长递增子序列长度的开始

LeetCode 674. 最长连续递增序列(Longest Continuous Increasing Subsequence) 18

674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 每日一算法2019/5/21Day 18LeetCode674. Longest Conti

【算法】——查找:最长连续递增子序列(部分有序)

找出在数组中的最长递增子序列 数组:1,9,2,5,7,3,4,6,8,0 最长递增子序列:3,4,6,8 思路: 遇到大的就移动,如果在某一个位置变小了就计算这一段的长度(双指针)不停更新最大的length一个在前线,一个在后面作为游标,最后结束了看一下战线拉了有多长 public class 最长递增子序列 { public static void main(String[] args) { int []arr = {0,1,0,1,2,3,1,2,0,1,2,3,4,5,1}; getLa

LeetCode - 最长连续递增序列

题目描述: 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3.尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的,因为5和7在原数组里被4隔开. 示例 2: 输入: [2,2,2,2,2] 输出: 1 解释: 最长连续递增序列是 [2], 长度为1. code: public class Solution { public int findLengthOfLCIS(i

解题报告 HDU1087 Super Jumping! Jumping! Jumping!

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a