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 ...
随机推荐
- haploview出现“more than two alleles”的解决方法
弹出“more than two alleles”的错误是因为ped文件中一个SNP位点上存在两个以上的等位基因,haploview连锁分析时默认为只有两个等位基因,因此我们要去掉超过两位等位基因的S ...
- python 文件拷贝
用python实现了一个小型的自动发版本的工具.这个“自动发版本”有点虚, 只是简单地把debug 目录下的配置文件复制到指定目录,把Release下的生成文件复制到同一指定,过滤掉不需要的文件夹(. ...
- 图解Android Studio导入Eclipse项目源码
方法/步骤 打开Android Studio,在主页面中选择"File"->"New"->"Import project...&quo ...
- 【随笔】内存 & I/O检测相关
缺页中断 缺页中断属于内部中断,也就是异常.细分的话属于异常中的故障. 在执行一条指令时,如果发现他要访问的页没有在内存中(存在位为0),那么停止该指令的执行,并产生一个页不存在异常,对应的故障处理程 ...
- js 去掉字符串前后空格
//去左空格; function ltrim(s){ return s.replace(/(^\s*)/g, ""); } //去右空格; function rtrim(s){ r ...
- 1029. Median (25)
分析: 考察归并排序,用简单的快排会超时. #include <iostream> #include <stdio.h> #include <algorithm> ...
- Vi Command 【转载】
原文: http://www.cnblogs.com/Jesenwuzj/archive/2010/03/18/1688776.html Vi中文手册 1.vi的基本概念 基本上vi可以分为三种状态, ...
- CAST 类型转换应用
1: select 2: ID,SystemID,Department, 3: case Number when 0 then '若干' else CAST(Number as varchar)+'人 ...
- 【Visual Lisp】Visual Lisp属性与方法
说明:Visual Lisp属性的获取.赋值和方法的执行有多种形式.然而对于初学者来说一次性就要全部掌握显然是没有必要的,有时候每种方法都是通用的功能都一样我们就没有必要把所有方法都记住.我们只需要掌 ...
- C++字符串常量
C++字符串常量 当一个字符串常量出现于表达式中时,它的值是个指针常量.编译器把这个指定字符的一份copy存储在内存的某个位置(全局区),并存储一个指向第一个字符的指针. #include <i ...


