hdu 1087 动态规划之最长上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1087
![]() |
||||||||||||||||
|
||||||||||||||||
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 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. 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
Recommend
|
#include<stdio.h>
#define N 1001
int dp[N];
int value[N];
int n,max;
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=; i<n; i++)
{
scanf("%d",&value[i]);
}
dp[]=max=value[];
for(i=; i<n; i++)
{
dp[i]=value[i];
for(j=; j<i; j++)
{
if(value[i]>value[j])
{
if(dp[i]<dp[j]+value[i])//动态规划的精髓是把问题分成子问题,这样,因为j<i,那么dp[j]一定是一个上升序列
dp[i]=dp[j]+value[i];
}
}
if(dp[i]>max)
max=dp[i];
}
printf("%d\n",max);
}
return ;
}
hdu 1087 动态规划之最长上升子序列的更多相关文章
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- HDU 1159 Common Subsequence (动态规划、最长公共子序列)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1243 反恐训练营 (动态规划求最长公共子序列)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 动态规划之最长公共子序列(LCS)
转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1513 Palindrome(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 解题报告:给定一个长度为n的字符串,在这个字符串中插入最少的字符使得这个字符串成为回文串,求这个 ...
- 动态规划:最长上升子序列(LIS)
转载请注明原文地址:http://www.cnblogs.com/GodA/p/5180560.html 学习动态规划问题(DP问题)中,其中有一个知识点叫最长上升子序列(longest incre ...
- 动态规划之最长公共子序列LCS(Longest Common Subsequence)
一.问题描述 由于最长公共子序列LCS是一个比较经典的问题,主要是采用动态规划(DP)算法去实现,理论方面的讲述也非常详尽,本文重点是程序的实现部分,所以理论方面的解释主要看这篇博客:http://b ...
随机推荐
- pause 和 title
-------siwuxie095 pause 暂停批处理程序,并显示:请按任意键继续- 暂停高级技巧: pause>nul 只暂停,不显示任何信息,且光标移到下一行 如果不想用默认提示语:请按 ...
- HttpServletResponse
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...
- redis Transaction支持
前面主要介绍了redis数据类型,这里讲下事务问题 NoSQL都不支持事务,虽然Redis的Transactions提供的并不是严格的ACID的事务(比如一串用EXEC 提交执行的命令,在执行中服务器 ...
- 問題排查:在 ServiceModel 客戶端配置部份中,找不到名稱 和協定 的終結點元素。
同樣都是刪掉服務參考再重建重編譯重發行,為什麼之前幾次都沒事? 這次只不過是刪掉服務參考,然後換了個名稱重建而已,做完就變這樣? 後來發現問題出在 app.config,因為之前 app.config ...
- ABP的工作单元
http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work 工作单元位于领域层. ABP的数据库连接和事务处理: 1,仓储类 ASP ...
- caffe 安装在win 7 vs2015 无gpu的安装方式-是无法安装 的
网上多数是vs2012或者vs2013上安装方式,带NA-显卡的需要安装CUDA7.5,安装cuDNN4,cuDNN. 一 :下载caffe源码(microsoft版) 下载地址:https://gi ...
- hp小机定位网卡位置
rad已经被olrad取代 HPUX下定位网卡位置 一台HP小型机,可能配了多块网卡,在系统中以la ...
- Int16, Int32, Int64 范围
Int16, 等于short, 占2个字节. -32768 32767 Int32, 等于int, 占4个字节. -2147483648 2147483647 Int64, 等于long, 占8个字节 ...
- QEMU/KVM功能测试
最近在对QEMU/KVM在HP服务器进行功能测试,项目刚刚启动,遇到不少问题,从Git上拿到最新的source build进行测试,在RHEL7.0a3 + Kernel version3.10 + ...
- 第六次课:springMVC与spring的集成
spring在项目中起到了管理bean的作用,即可以通过配置,让系统自动创建所需的对象,通过一定的方式引用系统创建的对象,对象的创建和引用都是由spring自动完成的,用户不必参与,可以直接引用. 实 ...