题目

参考网上的代码的、、、

//要找到所有序列中的最长的公共子序列,
//定义状态dp[i]为在第一个序列中前i个数字中的最长公共子序列的长度,
//状态转移方程为dp[i]=max(dp[i],dp[j]+1); j<i //先预处理出两个数在所有序列中的位置关系,
//例如两个数a和b,只要在任意一个序列中a在b的后面,则记after[a][b]=1。 //在递推的时候如果!after[a][b],则进行状态转移。 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ; int a[][];
int after[][];
int dp[];
int main () {
int n,k;
scanf("%d%d",&n,&k);
int ii=;
for(int i=;i<k;i++)
{
for(int j=;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
memset(after,,sizeof(after));
memset(dp,,sizeof(dp));
for(int i=;i<k;i++)
{
for(int j=;j<n;j++)
{
for(int k=j+;k<n;k++)
{
after[a[i][k]][a[i][j]]=; //存在 k在j后面
}
}
} int ans=; //直接对1~n进行状态转移不可以
//要根据第一行来dp
for(int i=;i<n;i++)
{
dp[i]=;
for(int j=;j<i;j++)
{
if(after[a[][j]][a[][i]]==)dp[i]=max(dp[i],dp[j]+);
}
ans=max(dp[i],ans);
}
printf("%d\n",ans);
return ;
}

codeforces 463D Gargari and Permutations(dp)的更多相关文章

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

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

  2. Codeforces 463D Gargari and Permutations

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

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

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

  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 - 285E: Positions in Permutations(DP+组合数+容斥)

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

  6. CF463D Gargari and Permutations dp

    给定 $n<=10$ 个 $1$~$n$ 的排列,求这些排列的 $LCS$. 考虑两个排列怎么做:以第一个序列为基准,将第二个序列的元素按照该元素在第一个序列中出现位置重新编号. 然后,求一个 ...

  7. Codeforces 463D

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

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

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

  9. [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)

    [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...

随机推荐

  1. HTML5 API 之 history

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  2. 内核同步机制 RCU

    Evernote分享地址:http://www.evernote.com/shard/s133/sh/8807320d-f54d-4e90-a31b-e2a3d35509ee/7539dc3931b8 ...

  3. poj 1338 Ugly Numbers

    原题链接:http://poj.org/problem?id=1338 优先队列的应用,如下: #include<cstdio> #include<cstdlib> #incl ...

  4. android开发系列之代码整洁之道

    说起代码整洁之道,想必大家想到更多的是那本经典重构书籍.没错,记得当时自己读那本书的时候,一边结合项目实战,一边结合书中的讲解,确实学到了很多东西,对我自己的编码风格影响极深.随着时间的流逝,书中很多 ...

  5. C# socket 实现消息中心向消息平台 转发消息 (修改)

    using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using ...

  6. urllib3 PoolManager

    A pool manager is an abstraction for a collection of ConnectionPools.If you need to make requests to ...

  7. SQLite数据库的基本API函数

    1 .打开数据库: 说明:打开一个数据库,文件名不一定要存在,如果此文件不存在, sqlite 会自动创建.第一个参数指文件名,第二个参数则是定义的 sqlite3 ** 结构体指针(关键数据结构), ...

  8. xml之XSLT

     1.XSLT是什么  XSLT是XSL的子集,XSL是样式表.XSLT的作用:将XML文档转化成HTML,做的是中间转换者. 而主要需要学习的是XSLT(XSLTransformation).  2 ...

  9. java笔试题(4)

    abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized? abstract的method 不可以是static的,因为抽象的方法是要被子 ...

  10. 【每日scrum】NO.4

    1.掌握了如何求两点间的最短距离这个算法.