http://codeforces.com/problemset/problem/463/D

题意:给出k个排列,问这k个排列的最长公共子序列的长度。

思路:只考虑其中一个的dp:f[i]=max(f[j]+1),其中i这个位置的元素在其他排列里面的位置比j这个位置的元素在其他排列里面位置要靠前。

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int n,m,a[][],pos[][],f[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();
for (int i=;i<=m;i++)
for (int j=;j<=n;j++)
a[i][j]=read();
for (int i=;i<=m;i++)
for (int j=;j<=n;j++)
pos[i][a[i][j]]=j;
for (int i=;i<=n;i++){
f[i]=;
for (int j=;j<i;j++)
if (f[j]+>f[i]){
bool flag=;
for (int k=;k<=m;k++)
if (pos[k][a[][i]]<pos[k][a[][j]]) flag=;
if (flag) f[i]=f[j]+;
}
}
int ans=;
for (int i=;i<=n;i++)
ans=std::max(f[i],ans);
printf("%d\n",ans);
return ;
}

Codeforces 463D Gargari and Permutations的更多相关文章

  1. Codeforces 463D Gargari and Permutations(求k个序列的LCS)

    题目链接:http://codeforces.com/problemset/problem/463/D 题目大意:给你k个序列(2=<k<=5),每个序列的长度为n(1<=n< ...

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

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

  3. codeforces 463D Gargari and Permutations(dp)

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

  4. 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相应的字符 ...

  5. Codeforces 463D

    题目链接 D. Gargari and Permutations time limit per test 2 seconds memory limit per test 256 megabytes i ...

  6. 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 ...

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

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

  8. codeforces Gargari and Permutations(DAG+BFS)

    /* 题意:求出多个全排列的lcs! 思路:因为是全排列,所以每一行的每一个数字都不会重复,所以如果有每一个全排列的数字 i 都在数字 j的前面,那么i, j建立一条有向边! 最后用bfs遍历整个图, ...

  9. CodeForces 463D DP

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

随机推荐

  1. POJ3683 Falsita

    http://poj.org/problem?id=3683 思路:2-SAT,输出任意一组方案,O(m+n) #include<cstdio> #include<iostream& ...

  2. netcat

    一.概述 netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶.netca ...

  3. 学习javascript基础知识系列第二节 - this用法

    通过一段代码学习javascript基础知识系列 第二节 - this用法 this是面向对象语言中的一个重要概念,在JAVA,C#等大型语言中,this固定指向运行时的当前对象.但是在javascr ...

  4. php 实现购物车

    <?php class Cart{     public function Cart() {         if(!isset($_SESSION['cart'])){             ...

  5. NetAnalyzer笔记 之 二. 简单的协议分析

    [创建时间:2015-08-27 22:15:17] NetAnalyzer下载地址 上篇我们回顾完了NetAnalyzer一些可有可无的历史,在本篇,我决定先不对NetAnalyzer做介绍,而是先 ...

  6. 使用python监听、模拟鼠标键盘事件

    最近守望职业选手疑似开挂事件挺热闹的,在下小菜一枚,并不能从视频中看出端倪.看了一些关于外挂的讨论,自动点射和压枪只需在鼠标驱动上做些改动即可,自瞄或其他高级功能则需要读内存或修改游戏文件,检测也更容 ...

  7. 响应式布局:Flexbox应用总结

    距离上篇文章<布局神器:Flexbox>的发表已有一周时间,转眼这周又到了周五(O(∩_∩)O~~): 习惯性在周五对自己的一周工作进行下总结,记录下这周值得被纪念的工作事件,无论是好的, ...

  8. [原创]Web前端开发——让ie 7 8支持表单的placeholder属性

    今天在写页面的时候,测试低版本浏览器时,发现input写的placeholder显示的是空白,所以特意写了一个普遍试用的方法来让低版本浏览器支持这个属性. 博主建了一个技术共享qq群:,因为目前人数还 ...

  9. sublime怎么实现函数之间的跳转

    1.安装ctags应用程序. 到CTags的官方站点下载最新版本号,将解压后的ctags.exe放到系统环境变量的搜索路径中.通常是C:\windows\system32. 假设你想放到其它目录中,记 ...

  10. C语言的学习-基础知识点

    ---BOOL BOOL BOOL a = YES; printf("%d\n", a); a = NO; printf("%d", a); , b = ; B ...