部分分做法很多,但每想出来一个也就多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. 测试数据库DG搭建为正式库以后做准备

    Data guard 部署 1.系统准备(备库只需建立数据库软件) 两台操作系统 oracle linux 7 Node1 172.16.70.191 Node2 172.16.70.192 Orac ...

  2. 解析 Array.prototype.slice.call(arguments,0)

    Array.prototype.slice.call(arguments,0) 经常会看到这段代码用来处理函数的参数 网上很多复制粘帖说:Array.prototype.slice.call(argu ...

  3. 3中转换JSON数据的方式

    一:前言 来公司一个星期,把最近做的东西梳理下,并把觉得有必要的知识点记载下,现在传数据很多都是用JSON来传数据,所以我就找了集中传json的方式,其实是有五种的,但是有一个我没有用过,太陌生了,上 ...

  4. RPC-Thrift(三)

    TProtocol TProtocol定义了消息怎么进行序列化和反序列化的. TProtocol的类结构图如下: TBinaryProtocol:二进制编码格式: TCompactProtocol:高 ...

  5. 【uva1380 - 一个调度问题】思路题+树形dp

    [题意] 有n<=200个恰好需要一天完成的任务,要求用最少的时间完成所有任务.任务可以同时完成.但是有一些约束,分有向和无向两种,其中A-->B表示A必须在B前面完成,而A--B表示A和 ...

  6. 汕头市队赛 yyl杯1 T1

    A SRM 05 - YYL 杯 R1 背景 傻逼题 描述 给一个序列,序列里只有两种元素1和2.现在要从序列里选出一些非空子序列使得子序列里两种元素数量相同.问有多少种方案数? 输入格式 多组数据 ...

  7. [转]树莓派gpio口控制

    0.前言     树莓派现在越来越火,网上树莓派的资料也越来越多.树莓派源自英国,国外嵌入式开源领域具有良好的分享精神,树莓派各种集成库也层出不穷,下面推荐几个. [[开发语言]——python [[ ...

  8. [Leetcode Week8]Subsets

    Subsets 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/subsets/description/ Description Given a set ...

  9. EF选择Mysql数据源

    EF添加ADO.NET实体模型处直接选择Mysql数据源 最近想到EF是连接多数据库的orm框架,于是就想测试下.查了一堆网上资料后,测试连接mysql成功.步骤如下: 1.在你项目Model层中nu ...

  10. [ python ] 使用sys模块实现进度条

    在写网络IO传输的时候, 有时候需要进度条来显示当前传输进度,使用 sys 模块就可以实现: sys.stdout.write() 这个函数在在控制台输出字符串不会带任何结尾,这就意味着这个输出还没有 ...