bzoj1046 HAOI2007 上公升序列

2022-09-18 10:42:21 字數 843 閱讀 1276

首先是o(nlogn) 的最長上公升子串行,我居然一直不會。。。。(霧)。

用乙個maxv[i] 陣列表示長度為i的上公升子串行的第乙個數的最大值,這樣就可以二分求當前上公升子串行的長度了。

注意這道題字典序最小是指下標。

#include#include

#include

using

namespace

std;

const

int maxn = 10000 + 10

;const

int inf = 0x3f3f3f3f

;int

a[maxn],maxv[maxn],f[maxn],res[maxn];

intn,m,maxlen;

void

input()

void

build()

maxlen = max(maxlen,f[i] =cur);

maxv[cur] =max(maxv[cur],a[i]);

}}void

solve()

res[cnt=0] = -inf;

for(int i = 1; i <=n && cnt < len; i++)

if(f[i] >= len-cnt && a[i] >res[cnt])

res[++cnt] =a[i];

for(int i = 1; i < cnt; i++) printf("

%d "

,res[i]);

printf(

"%d\n

",res[cnt]);

}}int

main()

BZOJ 1046 HAOI 上公升序列

1046 haoi2007 上公升序列 time limit 10 sec memory limit 162 mbsubmit 5376 solved 1862 submit status discuss description 對於乙個給定的s 若有p 滿足 x1 x2 xm 且 ax1 2 出s...

bzoj 1046 HAOI2007 上公升序列

首先用f i 表示從i開始的最長上公升子串行的長度 注意這裡和平時的不一樣,是以i開頭而不是以1到i 這就相當於倒序做一遍最長下降子串行 然後要用到貪心 首先假設要取長度為x的,如果比算出來的max大 max正序倒序都一樣的 肯定無解 然後從頭開始取,因為從頭取的下標字典序最小,如果a i 比上乙個...

BZOJ1046 HAOI2007 上公升序列

portal 首先是否存在很容易。考慮如何輸出最小字典序的方案。注意。是位子的字典序,不是值。那麼這樣的話,倒過來做一遍最長下降子串行。f i 表示以 i 開頭的最長上公升子串行長度 找答案的時候就順著找,每次滿足條件就輸出。include include include define n 1000...