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 ...
随机推荐
- BZOJ2045: 双亲数
2045: 双亲数 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 602 Solved: 275[Submit][Status] Descripti ...
- POJ1159 Palindrome(数位DP)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 58277 Accepted: 20221 Desc ...
- c语言const
const关键字 const和指针结合,共有4种形式 const int *p; p是一个指针,指针指向一个int型数据.p所指向的是个常量. int const *p; p是一个指针,指针指向一个i ...
- day54
今天复习时间15个小时 那都做了什么呢 数学2000试卷 阅读2篇整理 翻译2个视频 政治背诵加视频 数学综合5个证明 作文两篇 c语言结构体以及简单总结 博客园日记 数据结构 好了 感觉也没有做什么 ...
- <php>Ajax基本格式
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- altium designer 原理图复制出错
复制原理图的时候最后弹出这种错误 InvalidParameter at 2510219C. AdvSch.dll, Base Address: 24C80000. Exception Occurre ...
- 在Ubuntu上下载、编译和安装Android最新内核源代码(Linux Kernel)
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6564592 在前一篇文章提到,从源代码树下载下 ...
- .NET基础拾遗(3)字符串、集合和流2
二.常用集合和泛型 2.1 int[]是值类型还是引用类型? .NET中无论是存储值类型对象的数组还是存储引用类型的数组,其本身都是引用类型,其内存也都是分配在堆上的.所有的数组类型都继承自Syste ...
- DEV GridControl 鼠标单击事件
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { ...
- [Asp.Net]状态管理(Session、Application、Cache、Cookie 、Viewstate、隐藏域 、查询字符串)
Session: 1. 客户在服务器上第一次打开Asp.Net页面时,会话就开始了.当客户在20分钟之内没有访问服务器,会话结束,销毁session.(当然也可以在Web.config中设置缓存时间 ...