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相应的字符在k个排列中都保持同样的相对位置}
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
const int NN=2222;
int f[7][NN];
int maxn;
int anti[7][NN];
int dp[NN];
int main(){
#ifndef ONLINE_JUDGE
freopen("/home/rainto96/in.txt","r",stdin);
#endif
int n,k;cin>>n>>k;
for(int i=1;i<=k;i++)
for(int j=1;j<=n;j++){
cin>>f[i][j];
anti[i][f[i][j]]=j;
}
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
bool flag=false;
for(int m=1;m<=k;m++)
if(anti[m][f[1][i]]<anti[m][f[1][j]])
flag=true;
if(flag) continue;
dp[i]=max(dp[i],dp[j]+1);
}
maxn=max(maxn,dp[i]);
}
cout<<maxn<<endl;
return 0;
}
CF 463D Gargari and Permutations [dp]的更多相关文章
- codeforces 463D Gargari and Permutations(dp)
题目 参考网上的代码的... //要找到所有序列中的最长的公共子序列, //定义状态dp[i]为在第一个序列中前i个数字中的最长公共子序列的长度, //状态转移方程为dp[i]=max(dp[i],d ...
- 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
http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...
- Codeforces 463D Gargari and Permutations(求k个序列的LCS)
题目链接:http://codeforces.com/problemset/problem/463/D 题目大意:给你k个序列(2=<k<=5),每个序列的长度为n(1<=n< ...
- CF463D Gargari and Permutations dp
给定 $n<=10$ 个 $1$~$n$ 的排列,求这些排列的 $LCS$. 考虑两个排列怎么做:以第一个序列为基准,将第二个序列的元素按照该元素在第一个序列中出现位置重新编号. 然后,求一个 ...
- 【题解】POJ2279 Mr.Young′s Picture Permutations dp
[题解]POJ2279 Mr.Young′s Picture Permutations dp 钦定从小往大放,然后直接dp. \(dp(t1,t2,t3,t4,t5)\)代表每一行多少人,判断边界就能 ...
- CF 983B XOR-pyramid(区间dp,异或)
CF 983B XOR-pyramid(区间dp,异或) 若有一个长度为m的数组b,定义函数f为: \(f(b) = \begin{cases} b[1] & \quad \text{if } ...
- Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题
http://codeforces.com/contest/463/problem/D 求k个序列的最长公共子序列. k<=5 肯定 不能直接LCS 网上题解全是图论解法...我就来个dp的解法 ...
- 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 ...
随机推荐
- ssm框架常见问题
搭建SSM框架时,总是遇到这样那样的问题,有的一眼就能看出来,有的需要经验的积累.现将自己搭建SSM框架时遇到的典型问题总结如下: 一.Struts2框架下的action中无法使用@Autowired ...
- CSS基础-DAY1
CSS 概述CSS 指层叠样式表 (Cascading Style Sheets),样式定义了如何显示 HTML文件中的标签元素,CSS是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标 ...
- Sass 和 SCSS 有什么区别?
Sass 官网上是这样描述 Sass 的: Sass 是一门高于 CSS 的元语言,它能用来清晰地.结构化地描述文件样式,有着比普通 CSS 更加强大的功能. Sass 能够提供更简洁.更优雅的语法, ...
- Codeforces Round #461 (Div. 2)
A - Cloning Toys /* 题目大意:给出两种机器,一种能将一种原件copy出额外一种原件和一个附件, 另一种可以把一种附件copy出额外两种附件,给你一个原件, 问能否恰好变出题目要求数 ...
- Codeforces Round #295 (Div. 2)C - DNA Alignment 数学题
C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- mac下git+maven+jenkins自动打包发布
随着springboot+springcloud(dubbo)越来越多人使用,流行的微服务的概念越来越深入人心.分布式部署越来越复杂,给手动发布带来很大工作量.为了方便前期测试和后期线上部署更新,可使 ...
- POJ 3468 A Simple Problem with Integers (splay tree入门)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 47944 ...
- WhatsApp & Tasker for Android – Read & Write messages
WhatsApp & Tasker for Android – Read & Write messages The requirement for the automation is ...
- java 实现输出姓和名
package xiaojie; import java.util.Scanner; public class baiJiaXing { public static void main(String[ ...
- Java-子类扩展父类功能
class person { private String name; private int age; public String getname(){ return this.name; ...