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 ...
随机推荐
- Wireshark "The NPF driver isn’t running…"(可见的驱动本质上是一个系统服务,使用net start 启动)
前几天重装系统,装上了windows7 RC系统.昨天开始尝试装上了wireshark 这款很强大的网络监视软件,满心欢喜的打开,可是每次打开都会弹出“The NPF driver isn't run ...
- 关于bat文件语法
@echo offecho 当前盘符:%~d0echo 当前盘符和路径:%~dp0echo 当前批处理全路径:%~f0echo 当前盘符和路径的短文件名格式:%~sdp0echo 当前CMD默认目录: ...
- linux文件合并
第一:两个文件的交集,并集前提条件:每个文件中不得有重复行1. 取出两个文件的并集(重复的行只保留一份)2. 取出两个文件的交集(只留下同时存在于两个文件中的文件)3. 删除交集,留下其他的行1. c ...
- BZOJ2212: [Poi2011]Tree Rotations
2212: [Poi2011]Tree Rotations Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 391 Solved: 127[Submi ...
- jquery 的ready() 与window.onload()的区别
做web开发时常用Jquery中$(document).ready()和JavaScript中的window.onload方法,两者都是要在页面加载完成以后加载的方法,但是这两者还是有很大区别的.最近 ...
- cf437A The Child and Homework
A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Hive 6、Hive DML(Data Manipulation Language)
DML主要是对Hive 表中的数据进行操作的(增 删 改),但是由于Hadoop的特性,所以单条的修改.删除,其性能会非常的低所以不支持进行级操作: 主要说明一下最常用的批量插入数据较为常用的方法: ...
- mysql插入数据时,中文乱码
MySQL 插入数据时,中文乱码问题的解决(转) 当向 MySQL 数据库插入一条带有中文的数据形如 insert into employee values(null,'张三','female','1 ...
- (转)iOS Wow体验 - 第三章 - 用户体验的差异化策略
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第三章译文精选,其余章节将陆续放出.上一篇:Wow ...
- Android实现程序前后台切换效果
本文演示如何在Android中实现程序前后台切换效果. 在介绍程序实现之前,我们先看下Android中Activities和Task的基础知识. 我们都知道,一个Activity 可以启动另一个Act ...