部分分做法很多,但每想出来一个也就多5~10分。正解还不会,下面是各种部分分做法:

Subtask 1:k=1

LCS长度最长为1,也就是说不存在j>i和a[j]>a[i]同时成立。显然就是一个LDS,树状数组直接求即可。

Subtask 2:k=2

最多两个,也就是可以由两个LCS拼起来,f[i][j]表示第一个LCS以i结尾,第二个以j结尾的方案数,转移显然。

Subtask 3:k=2

树状数组优化DP,复杂度由$O(n^3)$降为$O(n^2 \log n)$

Subtask 4,5:B<=8

DP套DP:https://www.cnblogs.com/clnchanpin/p/7357564.html

一般与“子序列”同时出现,如最长上升自序列,最长公共自序列等。

Subtask 6,7:

一个显然的定理:一个序列的LCS最大为k意味着这个序列最少可以由k个不相交的LDS组成。

考虑网络流,下面(a,b)表示容量为a,费用为b的边。

拆点,in[x]向out[x]连(1,-1)的边,每次和下一个小于这个数的位置连(1,0)的边,增设源汇,最多增广k次即可。

$O(Kn^3)$

Subtask 8,9:

上面的方法点数为$n$,边数为$n^2$,启发我们用线段树优化建图。

这里用树状数组就行了。

点数$n\log n$,边数$n\log n$。

$O(K(n\log n)^2)$

Subtask 10,11,12:

Johnson多源最短路算法:

传统的Floyd是$O(n^3)$的,已经很优秀了。但是如果我们对每个点跑一次Dijkstra,可以得到$O(n^2\log m)$这个更好的复杂度。

但是Dijkstra不能跑有负权边的情况。

考虑增设超级源S并向每个点连长度为0的边,然后跑单源最短路,接着将每条边(u,v,w)改成(u,v,w+(dis[u]-dis[v])),其中dis[u]表示S到u的最短路。

这样跑Dijkstra就是正确的了,转移的时候记录pre方便最后求出最短路长度。

不了解如何运用到这道题上。

优化:可以直接用数组代替堆降低复杂度。

Subtask 13~20:

完全不理解的杨氏矩阵理论。

不断分析将复杂度依次降为:$O(n^2\log n+Q\log n)$,$O(n\sqrt{n}\log n)$,$O(n\sqrt{n\log n})$。

附:树状数组+网络流代码(15pts)

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=;
int x,y,fir[N],pre[N],a[N],b[N],inq[N],dis[N],n,m,cnt=;
int in[N],out[N],ans[N],BIT[N],S,T,cost,lim,obt,tot; struct edge{
int to,nxt,f,c;
edge () {}
edge (int x,int y,int z,int l){ to=y; nxt=fir[x]; f=z; c=l; fir[x]=cnt; }
}e[*N]; void add(int x,int y,int z,int l){ e[++cnt]=edge(x,y,z,l); e[++cnt]=edge(y,x,,-l); } bool spfa(){
int i,x; queue<int> q;
for(i=;i<=T;i++) dis[i]=;
dis[S]=; q.push(S);
while(!q.empty()){
x=q.front(); q.pop();
for(i=fir[x];i;i=e[i].nxt)
if(e[i].f&&dis[e[i].to]>dis[x]+e[i].c){
dis[e[i].to]=dis[x]+e[i].c; pre[e[i].to]=i;
if(!inq[e[i].to]) q.push(e[i].to),inq[e[i].to]=;
}
inq[x]=;
}
return dis[T]!=;
} int aug(){
int x,flow=1e9;
for(x=T;x!=S;x=e[pre[x]^].to) flow=min(flow,e[pre[x]].f);
for(x=T;x!=S;x=e[pre[x]^].to)
cost+=e[pre[x]].c*flow,e[pre[x]].f-=flow,e[pre[x]^].f+=flow;
return flow;
} int dinic(){ int res=; while(spfa()) res+=aug(); return res; } void modify(int p,int x){
for(;x<=obt;x+=x&-x){
tot++;
if(BIT[x]) add(tot,BIT[x],n,);
add(tot,p,,); BIT[x]=tot;
}
} void ask(int p,int x){ for (;x;x-=x&-x) if (BIT[x]) add(p,BIT[x],,); } int main(){
freopen("lis.in","r",stdin);
freopen("lis.out","w",stdout);
scanf("%d%d",&n,&m);
if (n>) { rep(i,,m) printf("0\n"); return ; }
rep(i,,n) scanf("%d",&a[i]),b[i]=a[i];
sort(b+,b+n+); obt=unique(b+,b+n+)-b-;
rep(i,,n) a[i]=lower_bound(b+,b+obt+,a[i])-b;
rep(i,,n) in[i]=i,out[i]=i+n,add(in[i],out[i],,-);
tot=*n;
for (int i=n;i;i--) ask(out[i],a[i]),modify(in[i],a[i]);
S=tot+; T=S+;
rep(i,,n) add(S,in[i],,),add(out[i],T,,);
cost=lim=;
while(spfa()) aug(),ans[++lim]=-cost;
while(m--) scanf("%d%d",&x,&y),printf("%d\n",ans[min(y,lim)]);
return ;
}

[CTSC2017]最长上升自序列(伪题解)(Dilworth's theorem+网络流)的更多相关文章

  1. 算法复习——求最长不下降序列长度(dp算法)

    题目: 题目背景 161114-练习-DAY1-AHSDFZ T2 题目描述 有 N 辆列车,标记为 1,2,3,…,N.它们按照一定的次序进站,站台共有 K 个轨道,轨道遵从先进先出的原则.列车进入 ...

  2. JDOJ 1929: 求最长不下降序列长度

    JDOJ 1929: 求最长不下降序列长度 JDOJ传送门 Description 设有一个正整数的序列:b1,b2,-,bn,对于下标i1<i2<-<im,若有bi1≤bi2≤-≤ ...

  3. [BZOJ1852] [MexicoOI06]最长不下降序列

    [BZOJ1852] [MexicoOI06]最长不下降序列 额我也不知道是不是水过去的...和网上的另一篇题解对拍过了,但是拍不出来... 经过和神仙的讨论基本可以确定是对的了 考虑如下贪心 (我将 ...

  4. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  5. [LeetCode] Longest Continuous Increasing Subsequence 最长连续递增序列

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  6. [Swift]LeetCode674. 最长连续递增序列 | Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  7. 问题 B: 【例9.3】求最长不下降序列(基础dp)

    问题 B: [例9.3]求最长不下降序列 时间限制: 1 Sec  内存限制: 128 MB提交: 318  解决: 118[提交][状态][讨论版][命题人:quanxing] 题目描述 设有由n( ...

  8. leecode 978. Longest Turbulent Subarray(最长连续波动序列,DP or 滚动数组)

    传送门:点我 978. Longest Turbulent Subarray A subarray A[i], A[i+1], ..., A[j] of A is said to be turbule ...

  9. 九度oj题目1342:寻找最长合法括号序列II

    题目1342:寻找最长合法括号序列II(25分) 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:886 解决:361 题目描述: 假如给你一个由’(‘和’)’组成的一个随机的括号序列,当然 ...

随机推荐

  1. 原生toolbar基本使用教程

    1.先写布局文件 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:title=" ...

  2. 解析json方式之net.sf.json

    前面转载了json解析的技术:fastjson,今天说下另外一种技术. 下载地址 本次使用版本:http://sourceforge.net/projects/json-lib/files/json- ...

  3. 团队代码中Bug太多怎么办?怎样稳步提高团队的代码质量

    最近负责的Android APP项目,由于团队成员变动.界面改版导致代码大幅修改等原因,产品发布后屡屡出现BUG导致的程序崩溃. 经过对异常统计和代码走读,BUG主要集中在空指针引起的NullPoin ...

  4. c++(类) this指针

    this指针的相关概念: this只能在成员函数中使用.全局函数,静态函数都不能使用this.实际上,成员函数默认第一个参数为T* const register this. 为什么this指针不能再静 ...

  5. NSMutableArray遍历删除注意事项

      for (int i = 0; i < [array count]; i++) { [array removeObjectAtIndex:i]; } 上面的遍历由于在remove操作之后ar ...

  6. Java中一些知识的归纳总结

    1.包装类型与基本数据类型的区别. Java语言是一个面向对象的语言,但是Java中的基本数据类型却是不面向对象的,这使得Java在实际使用时存在很多的不便,为了解决这个不足,在设计类时为每个基本数据 ...

  7. css划斜线

    http://stackoverflow.com/questions/18012420/draw-diagonal-lines-in-div-background-with-css

  8. hdu 1686 Oulipo (kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...

  9. python3 面向对象补充

    f = People('egon',18,'male') 非函数hasattr # hasattr(f,'name')getattr # getattr(f,'name')setattr # seta ...

  10. python3 正则表达式re模块

    正则表达式的功能:字符串的模糊匹配查询import re元字符 . ---->匹配除换行符意外的任意字符 ^ ---->匹配行首位置 $ ---->匹配行尾位置 关于重复的元字符 * ...