给定 $n<=10$ 个 $1$~$n$ 的排列,求这些排列的 $LCS$.

考虑两个排列怎么做:以第一个序列为基准,将第二个序列的元素按照该元素在第一个序列中出现位置重新编号.

然后,求一个 $LIS$ 即可.

现在是多个串,不妨也按照这个方法来做:

以第一个串为基准,其余串重新编号成该元素在第一个串中的出现位置.

那么,如果一个序列是 $n$ 个序列的 $LCS$,则满足两个条件:

1: 是重现编号后的 $LCS$

2: 这个 $LCS$ 还需是一个 $LIS$.

多了第二个限制,问题就简单了:令 $f[i]$ 表示这些新编号串以 $i$ 数字结尾的满足两个条件的最长长度.

转移什么的就简单了~

code:

#include <bits/stdc++.h>
#define N 1004
using namespace std;
void setIO(string s)
{
string in=s+".in";
string out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
struct node
{
int l,r;
}t[N];
int a[12][N],pos[N],f[N],L[12][N];
int main()
{
// setIO("seq");
int n,i,j,m,ans=1;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i) for(j=1;j<=n;++j) scanf("%d",&a[i][j]);
for(i=1;i<=n;++i) pos[a[1][i]]=i;
for(i=1;i<=m;++i) for(j=1;j<=n;++j) a[i][j]=pos[a[i][j]];
for(i=1;i<=m;++i) for(j=1;j<=n;++j) L[i][a[i][j]]=j;
f[1]=1;
for(i=2;i<=n;++i)
{
f[i]=1;
for(j=1;j<i;++j)
{
int flag=0;
for(int k=1;k<=10;++k) if(L[k][j]>L[k][i]) flag=1;
if(!flag) f[i]=max(f[i], f[j]+1), ans=max(ans, f[i]);
}
}
printf("%d\n",ans);
return 0;
}

  

CF463D Gargari and Permutations dp的更多相关文章

  1. codeforces 463D Gargari and Permutations(dp)

    题目 参考网上的代码的... //要找到所有序列中的最长的公共子序列, //定义状态dp[i]为在第一个序列中前i个数字中的最长公共子序列的长度, //状态转移方程为dp[i]=max(dp[i],d ...

  2. CF 463D Gargari and Permutations [dp]

    给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5).求这个k个数列的最长公共子序列的长度 dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符 ...

  3. [CF463D]Gargari and Permutations

    题目大意:给你$k(2\leqslant k\leqslant5)$个$1\sim n(n\leqslant10^3)$的排列,求它们的最长子序列 题解:将$k$个排列中每个元素的位置记录下来.如果是 ...

  4. 【题解】POJ2279 Mr.Young′s Picture Permutations dp

    [题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...

  5. Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题

    http://codeforces.com/contest/463/problem/D 求k个序列的最长公共子序列. k<=5 肯定 不能直接LCS 网上题解全是图论解法...我就来个dp的解法 ...

  6. Codeforces 463D Gargari and Permutations:隐式图dp【多串LCS】

    题目链接:http://codeforces.com/problemset/problem/463/D 题意: 给你k个1到n的排列,问你它们的LCS(最长公共子序列)是多长. 题解: 因为都是1到n ...

  7. Codeforces #264 (Div. 2) D. Gargari and Permutations

    Gargari got bored to play with the bishops and now, after solving the problem about them, he is tryi ...

  8. CodeForces - 285E: Positions in Permutations(DP+组合数+容斥)

    Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive in ...

  9. Codeforces 463D Gargari and Permutations

    http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...

随机推荐

  1. epoll_ctl函数的使用

    #include <sys/epoll.h> int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);作用: ...

  2. A Simple Question of Chemistry

    #include<stdio.h> int main() { int i, l; ]; ]; l = ; ) { l++; } ; a[i]!= && i<l; i+ ...

  3. 【LEETCODE】51、数组分类,简单级别,题目:581,830,1010,665

    package y2019.Algorithm.array; /** * @ClassName FindUnsortedSubarray * @Description TODO 581. Shorte ...

  4. enum类型的标签内容根据语言的取法

    昨天做了一个开发,说要取enum里面英文label 例如  JournalType   枚举值有   transfer\profit/loss 但是在中文的AX系统时会显示“转移\盈亏”, 但是客户又 ...

  5. golang---获取windows系统相关信息

    package main import ( "fmt" "net" "runtime" "strings" " ...

  6. ByteBuf源码

    ByteBuf是顶层的抽象类,定义了用于传输数据的ByteBuf需要的方法和属性. AbstractByteBuf 直接继承ByteBuf,一些公共属性和方法的公共逻辑会在这里定义.例如虽然不同性质的 ...

  7. ASP.NET Core 2.1 中的 HttpClientFactory (Part 3) 使用Handler实现传出请求中间件

    原文:https://www.stevejgordon.co.uk/httpclientfactory-aspnetcore-outgoing-request-middleware-pipeline- ...

  8. 1)NET CORE 重新认识 .net & .net core

    最近想系统性的学习下.net core ,在这之前我想再重新的认识下.net ,以及跟.net core 的区别. 有些我们开发.net经常用到的词汇可能还不是很了解,或者不能清晰的出他们的关系与却别 ...

  9. [C#] 生成中文电子通讯录

    var template = @" BEGIN:VCARD VERSION:2.1 N;CHARSET=gb2312:;{0};;; FN;CHARSET=gb2312:{0} TEL;CE ...

  10. AIR面向IOS设备的原生扩展

    来源:http://www.cnblogs.com/alex-tech/archive/2012/03/22/2411264.html ANE组成部分 在IOS平台中,ANE的组成部分基本分为AS 3 ...