题干:

Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear as described in the following algorithm (pseudocode).

procedure bubbleSortGraph()build a graph G with n vertices and 0 edgesrepeatswapped = falsefor i = 1 to n - 1 inclusive do:if a[i] > a[i + 1] thenadd an undirected edge in G between a[i] and a[i + 1]swap( a[i], a[i + 1] )swapped = trueend ifend foruntil not swapped /* repeat the algorithm as long as swapped value is true. */
end procedure

For a graph, an independent set is a set of vertices in a graph, no two of which are adjacent (so there are no edges between vertices of an independent set). A maximum independent set is an independent set which has maximum cardinality. Given the permutation, find the size of the maximum independent set of graph G, if we use such permutation as the premutation a in procedure bubbleSortGraph.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 105). The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n).

Output

Output a single integer — the answer to the problem.

Examples

Input

3
3 1 2

Output

2

Note

Consider the first example. Bubble sort swaps elements 3 and 1. We add edge (1, 3). Permutation is now [1, 3, 2]. Then bubble sort swaps elements 3 and 2. We add edge (2, 3). Permutation is now sorted. We have a graph with 3 vertices and 2 edges (1, 3) and (2, 3). Its maximal independent set is [1, 2].

题目大意:

冒泡排序,每交换一次就在图中建一条边,最终要求图中没有直接边相连的点集个数最大值,如果i<j && a[i]>a[j]就要交换。问你最大不相连的点有多少个。

解题报告:

类似于逆序对的概念,逆序对之间一定有边 所以这题就转化成类似于求非逆序对个数了,不一样的地方在于这题不是求个数,而是求最多的这样的点数,很明显转化成lis问题、、

话说训练的时候没想到这么多人会nlogn的lis。。。2333

虽然这是我做到过的第五个吧,,需要用到nlogn的、、这里总结一下分别是:

ZOJ 2319,51nod1134,HDU1025,codeforce270D

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int a[MAX],b[MAX];
int n;
int DP() {int len = 0;b[++len] = a[1];for(int i = 2; i<=n; i++) {if(a[i] >= b[len]) b[++len] = a[i];else {int pos = lower_bound(b+1,b+len+1,a[i]) - b;b[pos] = a[i];}}
//  for(int i = 1; i<=len; i++) printf("%d ",b[i]);return len;
}
int main()
{cin>>n;for(int i = 1; i<=n; i++) {scanf("%d",a+i);}printf("%d\n",DP());return 0 ;}

【CodeForces - 340D】Bubble Sort Graph (思维,nlogn最长上升子序列类问题)相关推荐

  1. c语言最长递增子序列nlogn,最长递增子序列

    问题定义: 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱).例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6, ...

  2. Java实现O(nlogn)最长上升子序列

    问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7....an,求它的一个子序列(设为s1,s2,...sn),使得这个子序列满足这样的性质,s1<s2<s3<...&l ...

  3. 【Effect CodeForces - 270D】Greenhouse (思维,最长非递减子序列(上升),对偶问题,考虑反面)

    题干: Emuskald is an avid horticulturist and owns the world's longest greenhouse - it is effectively i ...

  4. 【HDU - 5489】Removed Interval(离散化,权值线段树,思维,最长上升子序列)

    题干: Given a sequence of numbers A=a1,a2,-,aNA=a1,a2,-,aN, a subsequence b1,b2,-,bkb1,b2,-,bk of AA i ...

  5. 【CodeForces - 987C 】Three displays (dp,最长上升子序列类问题,三元组问题)

    题干: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaik ...

  6. 最长上升子序列(LIS) nlogn解法

    文章目录 经典DP解法O(n^2) dp+二分法(O(nlogn)) 最长上升子序列LIS:Longest increasing subsequence 题目链接:Leetcode300. 最长递增子 ...

  7. HDU - 5775 - Bubble Sort( 树状数组 + 思维 )

    题目链接:点击进入 题目 题意 问在给出的冒泡排序过程中,一个数到达的最右边位置与最左边位置距离差. 思路 对于一个数,位置 i ,假设右边比它小的数有 r 个,左边比它大的数有 l 个,最右边到达的 ...

  8. HDU5775 Bubble Sort树状数组

    题目链接:HDU5775 Bubble Sort Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java ...

  9. 排序 时间倒序_经典排序算法之冒泡排序(Bubble Sort)

    冒泡排序 ( Bubble Sort ) 冒泡排序,正如它的名字一样,未排序数组中的最大(小)值会依次往上浮.冒泡排序主要有两个基本步骤:相邻元素之间的比较 和 交换位置. 步骤分析: 令待排序序列为 ...

最新文章

  1. double a=25/2
  2. c++ fhog学习资料整理
  3. IOS开发基础知识--碎片39
  4. 开源项目成熟度分析工具-利用github api获取代码库的信息
  5. linux中setfacl命令,setfacl命令
  6. VMware linux虚拟机在线识别新添加磁盘
  7. jpa原生query_Spring Data JPA原生SQL查询
  8. nginx能访问html静态文件但无法访问php文件
  9. 凭运气接来的项目,怎样凭本事搞砸?
  10. 确定对象在使用前已经被初始化
  11. 彻底剖析C# 2.0泛型类的创建和使用
  12. Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace
  13. java数据结构与算法pdf下载
  14. PDMS中如何设置颜色规则
  15. php+uniapp(微信小程序版)实现电子签名及合同生成
  16. 小孔子内容管理系统V2.0测试
  17. 点击“安全删除硬件并弹出媒体”不显示可删除移动设备
  18. 大数据与区块链的爱恨情仇,一场技术界相爱相杀的爱恋!
  19. 基于人脸识别的考勤系统
  20. 阿拉伯字母及阿拉伯文排版规则

热门文章

  1. 【Breadth-first Search 】752. Open the Lock
  2. python task done_python queue task_done()问题
  3. 银行招聘网计算机类笔试,中国人民银行计算机类笔试模拟题
  4. codeql php,使用codeql 挖掘 ofcms
  5. armv8 汇编 绝对地址赋值_详解汇编语言B和LDR指令与相对跳转和绝对跳转的关系...
  6. python爬虫运行不出结果_请问这个为什么就是爬不到,运行之后电脑卡的不行,求大佬指导...
  7. vue 页面切换动画_Flutter Hero动画让你的APP页面切换充满动效 不一样的体验 不一样的细节处理...
  8. git add remote_最全的git常用命令(建议收藏)
  9. gentoo 安装时的网络配置
  10. asterisk 学习笔记1