题目链接:http://poj.org/problem?id=2533

Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 55459   Accepted: 24864

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

Source

Northeastern Europe 2002, Far-Eastern Subregion
 
 
O(n^2):
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e6+; int dp[MAXN], a[MAXN]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ; i<=n; i++)
scanf("%d",&a[i]); ms(dp, );
for(int i = ; i<=n; i++)
for(int j = ; j<i; j++)
if(j== || a[i]>a[j])
dp[i] = max(dp[i], dp[j]+); int ans = -INF;
for(int i = ; i<=n; i++)
ans = max(ans, dp[i]);
printf("%d\n",ans);
}
}
 
O(nlogn):
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e6+; int dp[MAXN], a[MAXN]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ; i<=n; i++)
scanf("%d",&a[i]); int len = ;
for(int i = ; i<=n; i++)
{
if(i== || a[i]>dp[len])
dp[++len] = a[i]; else
{
int pos = lower_bound(dp+,dp++len,a[i]) - (dp+);
dp[pos+] = a[i];
}
}
printf("%d\n",len);
}
}

POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)的更多相关文章

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

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

  2. 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)

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

  3. 【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)

    Longest Ordered Subsequence 搬中文 Descriptions: 给出一个序列,求出这个序列的最长上升子序列. 序列A的上升子序列B定义如下: B为A的子序列 B为严格递增序 ...

  4. [POJ2533]Longest Ordered Subsequence<dp>

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

  5. POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)

    传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...

  6. POJ - 2533 Longest Ordered Subsequence(最长上升子序列)

    d.最长上升子序列 s.注意是严格递增 c.O(nlogn) #include<iostream> #include<stdio.h> using namespace std; ...

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

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

  8. (线性DP LIS)POJ2533 Longest Ordered Subsequence

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

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

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

随机推荐

  1. include_once 问题

    最近在做微信小程序,在include_once 微信文件后,该方法return 前面会用特殊字符,导致我return 给前端的本来是json串变成了字符 解决方法 : ob_clean(); retu ...

  2. [Istio]流量管理API v1alpha3路由规则

    Istio提供一个API进行流量管理,该API允许用户将请求路由到特定版本的服务,为弹性测试注入延迟和失败,添加断路器等,所有这些功能都不必更改应用程序本身的代码.Istio 1.0中引入新的流量管理 ...

  3. 【Kubernetes】Kubernetes删除namespace后持续terminating状态

    删除isti和foo的配置文件之后,namespace持续terminating状态,此时也无法再创建istio-system的namespace namespace "istio-syst ...

  4. [luoguP1360] [USACO07MAR]黄金阵容均衡Gold Balanced L…

    传送门 真的骚的一个题,看了半天只会个前缀和+暴力.. 纯考思维.. 良心题解 #include <cstdio> #include <cstring> #include &l ...

  5. NOIP2014D2T2寻找道路(Spfa)

    洛谷传送门 这道题可以把边都反着存一遍,从终点开始深搜,然后把到不了的点 和它们所指向的点都去掉. 最后在剩余的点里跑一遍spfa就可以了. ——代码 #include <cstdio> ...

  6. 通过一个用户管理实例学习路由react-router-dom知识

    我们通过一个用户管理实例来学习react-router-dom 这个实例包括9个小组件 App.js 引入组件 Home.js 首页组件 User.js 用户管理组件 -  UserList.js 用 ...

  7. iOS 自动识别URL(链接)功能的实现

    功能需求  在做“沃迪康”聊天功能时,甲方要求发送的网址要自动识别.并点击能自动跳转 功能难点  在实现过程中,所有的文字都是动态获取的,设置富文本属性时,不能按照常规的方法 解决方式 如果只是文字, ...

  8. Xcode waring: no rule to process file *** 警告提示

    在编译程序的时候,Xcode给出了警告:warning: no rule to process file *** 类似的警告, 解决方法: 在[build Phases] -> [Compile ...

  9. 每日一个linux命令(1)

    ls命令: 1.        ls -l -R /home/文件夹   列出/home/文件夹下所有文件和目录的详细资料 2.        ls -l t*                     ...

  10. Org-mode五分钟教程ZZZ

    Table of Contents 1 源起 2 简介 2.1 获取 org-mode 2.2 安装 3 基础用法 3.1 创建一个新文件 3.2 简单的任务列表 3.3 使用标题组织一篇文章 3.4 ...