博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2533 Longest Ordered Subsequence
阅读量:6942 次
发布时间:2019-06-27

本文共 1718 字,大约阅读时间需要 5 分钟。

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 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

71 7 3 5 9 4 8

Sample Output

4 分析 最长上升子序列。定义d[i]为以第i个元素为起始的LIS,那么d[i]=max(d[j])+1,(j>i)。初始是d[n]=1。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const int maxn = 1e4+5;const int mod = 77200211+233;typedef pair
pii;#define X first#define Y second#define pb push_back//#define mp make_pair#define ms(a,b) memset(a,b,sizeof(a))const int inf = 0x3f3f3f3f;#define lson l,m,2*rt#define rson m+1,r,2*rt+1typedef long long ll;#define N 100010int a[maxn];int dp[maxn];int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); ms(dp,-1); for(int i=n;i>=1;i--){ dp[i]=1; int res=0; for(int j=i+1;j<=n;j++){ if(a[i]

 

 

转载于:https://www.cnblogs.com/fht-litost/p/8855310.html

你可能感兴趣的文章
为何在查询中索引未被使用 (Doc ID 1549181.1)
查看>>
安全之初——加解密、签名和证书理解
查看>>
【视频教程】一步步将AppBox升级到Pro版
查看>>
QNX多线程同步之Barrier(屏障)
查看>>
用Lua定制Redis命令
查看>>
使用MSTest进行单元测试
查看>>
SQL Server使用侦听器IP访问时遇到"The target principal name is incorrect. Cannot generate SSPI context"...
查看>>
Linux内核配置解析 - Boot options
查看>>
贝叶斯学习及共轭先验
查看>>
前端页面性能优化的几种方式
查看>>
Windows下安装Redis并注册为服务
查看>>
【BIEE】18_时间序列函数的使用
查看>>
从 HelloWorld 看 Java 字节码文件结构
查看>>
使用X.509数字证书加密解密实务(一)-- 证书的获得和管理
查看>>
HDU 5402 Travelling Salesman Problem(多校9 模拟)
查看>>
重装linuxserver简易流程
查看>>
思维导图软件
查看>>
Apple iOS MDM开发流程
查看>>
USB CDC & 可变形参
查看>>
mysql 的一点点记录
查看>>