Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 66763   Accepted: 29906

Description

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1a2, ..., aN) be any sequence (ai1ai2, ..., 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 file 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 file 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

最长递增子序列问题,水题。理解好状态转移式怎么得到就行了。
状态转移式是d(i) = max(dp[j] + 1,dp[i])(a[i] > a[j])(j < i) (如果为最长不下降子序列的话a[i] >= a[j]就行,并且j < i);其中dp[i]要先为1,因为无论如何这个子序列的长度的最小情况为1。
打表就行
对了,最后得到的dp[i]中i从1到n时,各自的dp[i]代表前i个数的最长递增子序列的最长长度。不一定dp[n]是最大的,要先比较,从中选出最大的。 C++ 代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = ;
int a[maxn],dp[maxn];
int main(){
int n;
memset(a,,sizeof(a));
scanf("%d",&n);
for(int i = ; i < n; i++){
cin>>a[i];
}
memset(dp,,sizeof(dp));
for(int i = ; i < n; i++){
dp[i] = ;
for(int j = ; j < i; j++){
if(a[i] > a[j] && dp[j] + > dp[i])
dp[i] = dp[j] + ;
}
}
int ans = -;
for(int i = ; i < n; i++){
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
return ;
}

(线性DP LIS)POJ2533 Longest Ordered Subsequence的更多相关文章

  1. POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  2. POJ2533——Longest Ordered Subsequence(简单的DP)

    Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...

  3. [POJ2533]Longest Ordered Subsequence<dp>

    题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...

  4. POJ2533 Longest Ordered Subsequence 【最长递增子序列】

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 32192   Acc ...

  5. poj-2533 longest ordered subsequence(动态规划)

    Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...

  6. POJ2533 Longest ordered subsequence

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41984   Acc ...

  7. POJ2533 Longest Ordered Subsequence (线性DP)

    设dp[i]表示以i结尾的最长上升子序列的长度. dp[i]=max(dp[i],dp[j]+1). 1 #include <map> 2 #include <set> 3 # ...

  8. POJ-2533.Longest Ordered Subsequence (LIS模版题)

    本题大意:和LIS一样 本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i) 参考代码: # ...

  9. POJ2533:Longest Ordered Subsequence(LIS)

    Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...

随机推荐

  1. matlab颜色映射colormap() pcolor()

    http://blog.csdn.net/qq_20823641/article/details/51711618

  2. python--使用pymyslq操作数据库

    1.安装pymysql 在命令行内输入 pip install pymysql : 2.pycharm连接mysql 在进行本文以下内容之前需要注意: 你有一个MySQL数据库,并且已经启动. 你有可 ...

  3. BZOJ1208[HNOI2004]宠物收养场——treap

    凡凡开了一间宠物收养场.收养场提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物. 每个领养者都希望领养到自己满意的宠物,凡凡根据领养者的要求通过他自己发明的一个特殊的公式,得出该领养者希望领 ...

  4. mpvue——Error: EPERM: operation not permitted

    报错 $ npm run build > mpvue@ build D:\wamp\www\webpack\mpvue\my-project > node build/build.js w ...

  5. Codeforces734 E. Anton and Tree

    传送门:>Here< 题意:给出一颗树,节点不是黑色就是白色,每次可以将一个颜色相同的块变颜色,问最少变几次才能让其变为同色 解题思路: 我们考虑由于每一次都是把同样颜色的色块进行变色,因 ...

  6. python查找读写文件

    import os ''' 跟据文件名称,后缀查找指定文件 path:传入的路径 filename:要查找的文件名 suffix:要查找的文件后缀 return :返回查找的文件路径 ''' file ...

  7. 各种MM(存储器)含义

    1.rom:read only memory 只读存储器 只能读,不能写. 2.ram:random access memory 随机存取存储器 可读可写. 3.fifo:first in first ...

  8. Java实现一个双向链表的倒置功能

    题目要求:Java实现一个双向链表的倒置功能(1->2->3 变成 3->2->1) 提交:代码.测试用例,希望可以写成一个Java小项目,可以看到单元测试部分 该题目的代码, ...

  9. 第一次使用cisco packet tracer

    搭建一个如图所示的网络,左边局域网是10.0.0.0网段,右边局域网是12.0.0.0网段,中间为广域网11.0.0.0网段 上面的成功了,但是不是很熟悉,下面重新来一遍 1.先用可视化界面建立一个如 ...

  10. luogu1397 [NOI2013]矩阵游戏 (等比数列求和)

    一个比较显然的等比数列求和,但有一点问题就是n和m巨大.. 考虑到他们是在幂次上出现,所以可以模上P-1(费马小定理) 但是a或c等于1的时候,不能用等比数列求和公式,这时候就要乘n和m,又要变成模P ...