返回项目列表

/note/ICPC笔记

ICPC笔记

当前项目读取 content/notes/ICPC笔记 下的 Markdown 文件。

ICPC笔记

LIS&LNDS

LIS&LNDS 核心思想: 维护一个数组 LIS 最长上升子序列 LNDS 最长不下降子序列 最长不上升,最长下降 序列 关系 二分 严格上升 < lower bound 不下降 ≤ upper bound 严格下降 对 a i 用 lower bound 不升 ≥ 对 a i 用 upper b...

LIS&LNDS

核心思想:

维护一个数组

f[k] = 长度为k的子序列最小结尾

LIS 最长上升子序列

vector<int> f;
for(int i=1;i<=n;i++){
    auto it=lower_bound(f.begin(),f.end(),a[i]);
    if(it==f.end())
        f.push_back(a[i]);
    else
        *it=a[i];
}

LNDS 最长不下降子序列

vector<int> f;
for(int i=1;i<=n;i++){
    auto it=upper_bound(f.begin(),f.end(),a[i]);
    if(it==f.end())
        f.push_back(a[i]);
    else
        *it=a[i];
}

最长不上升,最长下降

序列关系二分
严格上升<lower_bound
不下降upper_bound
严格下降>-a[i] 用 lower_bound
不升-a[i] 用 upper_bound

Dilworth的应用

最少不下降子序列覆盖链数=最长下降子序列大小