传送门

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

思路

  模板题

#include<stdio.h>
const int maxn = 1005;

int binary(int pos,int len,int *ans,int *dp)
{
	int left = 1,right = len;
	while (left < right)
	{
		int mid = left + ((right - left) >> 1);
		if (dp[mid] < ans[pos] )	left = mid + 1;
		else right = mid;
	}
	return right;
}

int main()
{
	int N,len = 1;
	int ans[maxn],dp[maxn];
	scanf("%d",&N);
	for (int i = 1;i <= N;i++)	scanf("%d",&ans[i]);
	dp[1] = ans[1];
	for (int i = 2;i <= N;i++)
	{
		if (ans[i] > dp[len])	dp[++len] = ans[i];
		else
		{
			int pos = binary(i,len,ans,dp);dp[pos] = ans[i];  //找到第一个大于等于ans[i]的位置,更新dp[pos]的最小值
			//pos = low_bound(dp+1,dp+len,ans[i]) - dp;
		}
	}
	printf("%d\n",len);
	return 0;
} 

POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)的更多相关文章

  1. poj 2533 Longest Ordered Subsequence 最长递增子序列

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...

  2. POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]

    题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...

  3. poj 2533 Longest Ordered Subsequence 最长递增子序列(LIS)

    两种算法 1.  O(n^2) #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  4. POJ 2533 Longest Ordered Subsequence 最长递增序列

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

  5. POJ 2533 Longest Ordered Subsequence(裸LIS)

    传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  6. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

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

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

  8. POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)

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

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

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

随机推荐

  1. Linux学期总结

    学习笔记链接 第一次 http://www.cnblogs.com/Spr1ngxx/p/4823573.html 第二次 http://www.cnblogs.com/Spr1ngxx/p/4842 ...

  2. 深入理解计算机系统(2.2)---布尔代数以及C语言上的位运算

    布尔代数上的位运算 布尔代数是一个数学知识体系,它在0和1的二进制值上演化而来的. 我们不需要去彻底的了解这个知识体系,但是里面定义了几种二进制的运算,却是我们在平时的编程过程当中也会遇到的.这四种运 ...

  3. ModernUI教程:目录 (完结)

    入门 My first Modern UI app (manually)                         第一个ModernUI应用(手动编写)(已完成) My first Moder ...

  4. nios II--实验3——led 100M硬件部分

    led_100M 硬件开发 新建原理图 参照实验二(led) QSys调用模块 参照实验二(led) 原理图添加IP模块 参照实验二(led),在调用PLL的时候需要修改系统和SDRAM的时钟频率为1 ...

  5. 彻底明白IP地址——IP地址的介绍

    彻底明白IP地址——IP地址的介绍 [ 作者:担子    转贴自:赛迪网    点击数:9692    更新时间:2004-12-22  ]   IP地址的介绍 1.IP地址的表示方法 IP地址 = ...

  6. 代码生成工具——CodeSmith

    1.绿色版软件下载:http://download.csdn.net/detail/laoge/6859701 2.破解说明:http://tieba.baidu.com/p/3373160396 3 ...

  7. Win7 64bit下32bit的 ODBC 数据源问题

    win764位有数据源,但是如果我们在win7 64bit中使用32位的数据源的时候,我们就需要对其进行配置,很有趣的是,64为的数据源我们可以在控制面板——系统与安全——管理工具——数据源,进入可对 ...

  8. 60-chmod 修改文件的权限

    修改文件的权限 chmod [options] who operator permission file-list (符号模式) chmod [options] mode file-list (绝对模 ...

  9. canvas三角函数直线运动

    var canvas = document.getElementById("canvas"); var cxt = canvas.getContext("2d" ...

  10. 关于insert /*+ append*/ 各种insert插入速度比较

    来源于:http://www.cnblogs.com/rootq/archive/2009/02/11/1388043.html SQL> select count(*) from t;COUN ...