Codeforces 463D Gargari and Permutations
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的更多相关文章
- Codeforces 463D Gargari and Permutations(求k个序列的LCS)
题目链接:http://codeforces.com/problemset/problem/463/D 题目大意:给你k个序列(2=<k<=5),每个序列的长度为n(1<=n< ...
- Codeforces 463D Gargari and Permutations:隐式图dp【多串LCS】
题目链接:http://codeforces.com/problemset/problem/463/D 题意: 给你k个1到n的排列,问你它们的LCS(最长公共子序列)是多长. 题解: 因为都是1到n ...
- codeforces 463D Gargari and Permutations(dp)
题目 参考网上的代码的... //要找到所有序列中的最长的公共子序列, //定义状态dp[i]为在第一个序列中前i个数字中的最长公共子序列的长度, //状态转移方程为dp[i]=max(dp[i],d ...
- 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相应的字符 ...
- Codeforces 463D
题目链接 D. Gargari and Permutations time limit per test 2 seconds memory limit per test 256 megabytes i ...
- 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 ...
- Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题
http://codeforces.com/contest/463/problem/D 求k个序列的最长公共子序列. k<=5 肯定 不能直接LCS 网上题解全是图论解法...我就来个dp的解法 ...
- codeforces Gargari and Permutations(DAG+BFS)
/* 题意:求出多个全排列的lcs! 思路:因为是全排列,所以每一行的每一个数字都不会重复,所以如果有每一个全排列的数字 i 都在数字 j的前面,那么i, j建立一条有向边! 最后用bfs遍历整个图, ...
- CodeForces 463D DP
Gargari got bored to play with the bishops and now, after solving the problem about them, he is tryi ...
随机推荐
- editplus配置详:
1:设置删除整行快捷键 2:设置背景颜色 3:php 开发环境 在 http://download.csdn.net/detail/vspeter/6002287 下载 editplus 的php语法 ...
- hdu 4055 Number String(dp)
Problem Description The signature of a permutation is a string that is computed as follows: for each ...
- C++中的重载、覆盖、隐藏
前几天面试时被问及C++中的覆盖.隐藏,概念基本答不上来,只答了怎么用指针实现多态,也还有遗漏.最终不欢而散.回来后在网上查找学习了一番,做了这个总结.其中部分文字借用了别人的博客,望不要见怪.引用的 ...
- Java操作属性文件,支持新增或更新多个属性
Java操作属性文件.支持新增或更新多个属性 一.更新或新增单个属性的方法 /** * 写入properties信息 * @param filePath 绝对路径(包含文件名称和后缀名) * @par ...
- Button和ImageButton
Button----button ImageButton----图片button 共同拥有特征: 都能够作为一个button产生点击事件 不同点 1. Button有text的属性.ImageButt ...
- [Redux] Extracting Container Components -- Complete
Clean TodoApp Component, it doesn't need to receive any props from the top level component: const To ...
- 使用WinAPI全局热键注册和全局模拟按键
一.全局热键注册 1.先引用DLL [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI publ ...
- c# 取得扩展名
string KZM=files[0].FileName.Substring(files[0].FileName.LastIndexOf(".") + 1);
- 正则去掉html标签
return System.Text.RegularExpressions.Regex.Replace(HTMLStr, "<[^>]*>", "&qu ...
- Oracle start with connect by prior 用法
Oracle start with connect by prior 用法 语法: select * from 表名 where 条件1 start with 条件2 connect by pr ...