HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33384 Accepted Submission(s): 15093
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
Author
lcy
1、HDU 1087
2、链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
3、总结:跳数字,求递增子序列使和最大,简单dp
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(a) ((a)>0?(a):-(a))
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
int dp[],value[]; //dp[i]指以dp[i]结尾的子序列的最大和 int main()
{
int n;
while((scanf("%d",&n)!=EOF),n)
{
memset(dp,,sizeof(dp));
//求出每个dp[i]
for(int i=;i<n;i++)
{
scanf("%d",&value[i]);
int maxn=-INF;
for(int j=;j<i;j++){
if((dp[j]>maxn)&&(value[j]<value[i])){
maxn=dp[j];
}
}
dp[i]=max(value[i],value[i]+maxn);
} int maxn=-INF;
for(int i=;i<n;i++)
{
if(maxn<dp[i])maxn=dp[i];
}
cout<<maxn<<endl; }
return ;
}
HDU 1087 简单dp,求递增子序列使和最大的更多相关文章
- hdu 1087 简单dp
思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<strin ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- HDU 1087 最长不下降子序列 LIS DP
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- HDU-1231 简单dp,连续子序列最大和,水
1.HDU-1231 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231 3.总结:水 题意:连续子序列最大和 #include<iostre ...
- Max Sum (hdu 1003 简单DP水过)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 1257 && hdu 1789(简单DP或贪心)
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> ...
- hdu 1423 最长公共递增子序列 LCIS
最长公共上升子序列(LCIS)的O(n^2)算法 预备知识:动态规划的基本思想,LCS,LIS. 问题:字符串a,字符串b,求a和b的LCIS(最长公共上升子序列). 首先我们可以看到,这个问题具有相 ...
- HDU 1708 简单dp问题 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1423 最长公共递增子序列
这题一开始把我给坑了,我还没知道LCIS的算法,然后就慢慢搞吧,幸运的是还真写出来了,只不过麻烦了一点. 我是将该题转换为多条线段相交,然后找出最多多少条不相交,并且其数值死递增的. 代码如下: #i ...
随机推荐
- git 本地仓库和远程仓库及本地分支和远程分支
从远程git仓库签出代码: $ git clone git://aaa.com/git_project.git (远程git服务器项目所在地址) 当你需要克隆远程项目到本地时,默认会把项目保存在名 ...
- 攻城狮在路上(壹) Hibernate(六)--- 通过Hibernate操纵对象(上)
一.Hibernate缓存简介: Session接口是Hibernate向应用程序提供的操纵数据接口的最主要接口,它提供了基本的保存.更新.删除和加载Java对象的方法. Session具有一个缓存, ...
- Arduino101学习笔记(十四)—— Flash库
一.一些API 1.打开文件 SerialFlashFile file; file = SerialFlash.open("filename.bin"); if (file) { ...
- 彻底删除Kafka中的topic
1.删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录 2.Kafka 删除topic ...
- JavaScript模拟函数重载
JavaScript是没有函数重载的,但是我们可以通过其他方法来模拟函数重载,如下所示: <!DOCTYPE html> <html> <head> <met ...
- Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
使用命令关闭占用80端口的程序 sudo fuser -k 80/tcp
- Android Java执行Shell命令
最新内容建议直接访问原文:http://www.trinea.cn/android/android-java-execute-shell-commands/ 主要介绍Android或Java应用中如何 ...
- Python与Hack
1.Python的函数:关键字def()表示函数开始,可以在括号内填写任何变量,然后这些变量会被以引用的方式传递给函数,也就是说,函数内对这些变量的任何改变都会影响它们在主调函数中的值: 2.迭代:用 ...
- DSP using Matlab 书内练习Example 2.1
先上代码,后出结果图. a. n = [-5:5]; x=2*impseq(-2,-5,5) - impseq(4,-5,5); set(gcf,'Color',[1,1,1]) % 改变坐标外围背景 ...
- git学习 git-flow
例子 初始化 在git init之后执行git init flow;接下来的命名约定建议使用默认值; 新特性 为即将发布的版本开发新功能特性. 这通常只存在开发者的库中. 增加新特性 git flow ...