日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 340D】Bubble Sort Graph (思维,nlogn最长上升子序列类问题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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

?

題目大意:

冒泡排序,每交換一次就在圖中建一條邊,最終要求圖中沒有直接邊相連的點(diǎn)集個數(shù)最大值,如果i<j && a[i]>a[j]就要交換。問你最大不相連的點(diǎn)有多少個。

解題報(bào)告:

? ? 類似于逆序?qū)Φ母拍?#xff0c;逆序?qū)χg一定有邊 所以這題就轉(zhuǎn)化成類似于求非逆序?qū)€數(shù)了,不一樣的地方在于這題不是求個數(shù),而是求最多的這樣的點(diǎn)數(shù),很明顯轉(zhuǎn)化成lis問題、、

? ?話說訓(xùn)練的時(shí)候沒想到這么多人會nlogn的lis。。。2333

? ?雖然這是我做到過的第五個吧,,需要用到nlogn的、、這里總結(jié)一下分別是:

? ? 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 ;} 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 340D】Bubble Sort Graph (思维,nlogn最长上升子序列类问题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。