hoj_10001_朴素DP(LIS)































Longest Ordered Subsequence
Time Limit: 1000ms, Special
Time Limit:
2500ms, Memory Limit:32768KB
Total submit users: 1937,
Accepted users: 1621
Problem 10001 : No
special judgement
Problem
description
A
numeric sequence of ai is ordered if
a1 < a2 < ... <
aN. Let the subsequence of the given numeric sequence
(a1, a2, ...,
aN) be any sequence
(ai1, ai2,
..., aiK), where 1 <=
i1 < i2 < ... <
iK <= N. For example, sequence (1, 7, 3,
5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many
others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5,
8).

Your program, when given the numeric sequence, must find the
length of its longest ordered subsequence.

Input
The
first line of input contains the length of sequence N. The second line
contains the elements of sequence - N integers in the range from 0 to
10000 each, separated by spaces. 1 <= N <= 1000
Output
Output
must contain a single integer - the length of the longest ordered
subsequence of the given sequence.

Sample
Input
7
1 7 3 5 9 4 8
Sample
Output
4

这是求lis的一道题,也一个最基本的O(n*n)的一维DP,更是我算法之路的开始~~~~~~

对于给定的a[N]数组,从1到n每次分别求对应a[i]的lis,最后即为最终的lis。

AC代码如下:


 1 #include<cstdio>
2 using namespace std;
3 int main()
4 {
5 int t;
6 int n;
7 int a[1005],b[1005];
8 while(scanf("%d",&n)!=EOF)
9 {
10 for(int i=0;i<n;i++)
11 scanf("%d",&a[i]);
12 b[0]=1;
13 for(int i=1;i<n;i++)
14 {
15 b[i]=1;
16 for(int j=0;j<i;j++)
17 {
18 if(a[i]>a[j] && b[j]+1>b[i])
19 {
20 b[i]=b[j]+1;
21 }
22 }
23 }
24 t=b[0];
25 for(int i=0;i<n;i++)
26 {
27 if(b[i]>t)
28 t=b[i];
29 }
30 printf("%d\n",t);
31 }
32 return 0;
33 }

hoj_10001_朴素DP(LIS),布布扣,bubuko.com

时间: 2024-11-05 12:25:39

hoj_10001_朴素DP(LIS)的相关文章

hduoj1025——dp, lis

hduoj1025——dp, lis Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17424    Accepted Submission(s): 4946 Problem Description JGShining's kingdom consist

hdu--(1025)Constructing Roads In JGShining&#39;s Kingdom(dp/LIS+二分)

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16047    Accepted Submission(s): 4580 Problem Description JGShining's kingdom consists of 2n(n is no mor

hdu----(1677)Nested Dolls(DP/LIS(二维))

Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2704    Accepted Submission(s): 802 Problem Description Dilworth is the world’s most prominent collector of Russian nested dolls: he

洛谷P1108 低价购买[DP | LIS方案数]

题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它.买的次数越多越好!你的目标是在遵循以上建议的前提下,求你最多能购买股票的次数.你将被给出一段时间内一支股票每天的出售价(2^16范围内的正整数),你可以选择在哪些天购买这支股票.每次购买都必须遵循“低价购买:再低价购买”的原则.写一个程序计算最大购买次数. 这里是某支股票的价格清单: 日期 1 2

HDU 1069 Monkey and Banana DP LIS变形题

http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两个参数作为长和宽,第三个是高. 然后要求把箱子搭起来,使得高度最高. 能搭的前提是下面那个箱子的长和宽都 > 上面那个箱子的. 思路: 因为同一个箱子可以产生6中不同的箱子,而每种最多选一个,因为相同的箱子最多只能搭起来一个. 那么可以把所有箱子都弄出来,排序,就是LIS的题目了. dp[i]表示以

HDU 5078 Revenge of LIS II(dp LIS)

Problem Description In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as po

hdu----(1257)最少拦截系统(dp/LIS)

最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19172    Accepted Submission(s): 7600 Problem Description 某 国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能 超过前一发的

Codeforces.264E.Roadside Trees(线段树 DP LIS)

题目链接 \(Description\) \(Solution\) 还是看代码好理解吧. 为了方便,我们将x坐标左右反转,再将所有高度取反,这样依然是维护从左到右的LIS,但是每次是在右边删除元素. 这样对于在p刚种的树,最多只有9棵树比它高,即它只会转移到这9棵树,除这9棵树外,它可以从1~p-1的任何树转移(其它9棵树除比它高的外 同样可以从它前面任何树转移). 我们把这9棵树的DP值暴力删掉,然后从低到高 从1~pos[h]-1转移并更新.按高度更新就只需要考虑位置合不合法了. 我们对位置

POJ3636Nested Dolls[DP LIS]

Nested Dolls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8323   Accepted: 2262 Description Dilworth is the world's most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow doll