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.

InputInput 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. 
OutputFor 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<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cmath>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const int inf = 1e9;
int a[1010], dp[1010], num[1010], n;
int calc( int sign ) { //求最长,nlog(n)fill( dp, dp+1010, inf );int ans = 0;for( int i = 0; i < n; i ++ ) {int index = lower_bound( dp, dp+ans, a[i]*sign ) - dp; //lower为求严格递增,upper为求非严格递增dp[index] = a[i]*sign;ans = max( ans, index + 1 );}return ans;
}
int lins() {return calc(1);
}
int lnds() {return calc(-1);
}
int calc_max() { //求最大,n^2int ans = 0;for( int i = 0; i < n; i ++ ) {dp[i] = a[i];for( int j = 0; j < i; j ++ ) {if( a[j] < a[i] ) {dp[i] = max( dp[i], dp[j]+a[i] );}}ans = max( ans, dp[i] );}return ans;
}
int main() {std::ios::sync_with_stdio(false);while( cin >> n ) {memset( num, 0, sizeof(num) );if( !n ) {break;}for( int i = 0; i < n; i ++ ) {cin >> a[i];}cout << calc_max() << endl;}return 0;
}

转载于:https://www.cnblogs.com/l609929321/p/9015980.html

最长上升子序列模板 hdu 1087 Super Jumping! Jumping! Jumping!相关推荐

  1. 三维最长上升子序列问题——HDU 1069 Monkey and Banana

    题目: A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a ...

  2. HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列的变形,子序列值最大)

    题意 wsw获得了与小姐姐约会的机会,同时也不用担心wls会发现了,可是如何选择和哪些小姐姐约会呢?wsw希望自己可以循序渐进,同时希望挑战自己的极限,我们假定每个小姐姐有一个"攻略难度值& ...

  3. hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular i ...

  4. hdu - 1087 - Super Jumping! Jumping! Jumping!

    题意:求最大升序和. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 -->>设d[i]表示以第i个数为终点的最大升序和,然后从第1 ...

  5. hdu 1087 Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular i ...

  6. hdu 1087 Super Jumping! Jumping! Jumping! 动态规划

    Super Jumping! Jumping! Jumping! Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K ...

  7. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  8. 最长公共子序列模板(LCS)和LICS模板

    递归式: 实例图解: 代码: 1 #include<stdio.h> 2 #include<string.h> 3 const int N=111; 4 int dp[N][N ...

  9. HDU 1087 [Super Jumping! Jumping! Jumping!]动态规划

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意:有N个格子,每个格子有数值.从原点开始跳,可以跳到任何一个位置:在某一个位置,只能跳到 ...

最新文章

  1. [转]使用 .NET Framework 2.0 在您的应用程序中支持证书
  2. Leetcode: Binary Tree Maximum Path Sum
  3. Android 热修复之DexPatch 介绍
  4. [模板]洛谷T3379 最近公共祖先(LCA) 倍增+邻接表
  5. 56PY宿迁味道这么可口
  6. 滑动返回-SwipeBackLayout
  7. AI未来 - 李开复 - 未来8成的工作受影响 - 读后感
  8. python常用中文分词方法_中文分词原理及常用Python中文分词库介绍
  9. 处理器管理及并发进程-多道程序设计
  10. Js实现背景图片切换
  11. php验证码图片不显示怎么办,php 验证码图片无法显示怎么办
  12. DBA的主要工作是什么
  13. python怎样实现量化选股?
  14. 游戏数据库版本更新神器Flyway
  15. 各种标点符号的英文怎么说
  16. c++期末考试样例(vm)
  17. drozer连接时出错,显示received an empty response from the agent
  18. 细粒度 文档图像版面分析
  19. C语言中chdir()使用
  20. 利用Python进行数据分析之金融数据的统计分析

热门文章

  1. 安装oh-my-zsh后terminal/iterm命令行终端前面用户计算机名消失之如何出现
  2. PAT 1082. 射击比赛 (20) - 乙级
  3. 给input文本框添加灰色提示文字
  4. 研发解决方案介绍#Tracing(鹰眼)
  5. Java中什么时候使用extends,什么时候使用implements?
  6. SSL证书相关技巧 -- 为什么有时候访问某些加密网站是不需要证书的?
  7. XP系统下IE7访问HTTPS网站提示“此网站的安全证书有问题”的解题思路
  8. 第一个C#程序—C#基础回顾
  9. 区分元素特性attribute和对象属性property
  10. CEF使用的几个注意点