http://codeforces.com/contest/463/problem/D

求k个序列的最长公共子序列。

k<=5

肯定 不能直接LCS

网上题解全是图论解法...我就来个dp的解法吧

首先,让我们创建的位置阵列的每个序列pos[k][N]。在这个数组,我们存储这n个数字(从1到n)在这k个序列中各个位置,然后按数大小排序。

DP [I]标记的最大长度共同序列,我们可以通过使用第一个序列的第i个元素生成。为此,我们遍历所有可能以前的编号(J),看看我们是否能延长DP [J]到DP [I]。

对于给定的J<I,只有在所有的序列中J的位置前与I,才能更新DP[I] = max(DP[J] + 1).

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
vector <int> pos[1005];
int dp[1005];
int main()
{
int n,k,x;
RD2(n,k);
for(int i = 0;i < k;++i){
for(int j = 1;j <= n;++j){
RD(x);
pos[x].push_back(j);
}
}
sort(pos+1,pos+n+1);
int ans = 1;
for(int i = 1;i <= n;++i)
dp[i] = 1;
for(int i = 2;i <= n;++i){
for(int j = 1;j < i;++j){
bool ok = true;
for(int l = 0;l < k;++l){
if(pos[j][l] > pos[i][l]){
ok = false;
break;
}
}
if(ok){
dp[i] = max(dp[j]+1,dp[i]);
}
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
return 0;
}

Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题的更多相关文章

  1. Codeforces Round #264 (Div. 2) C. Gargari and Bishops 主教攻击

    http://codeforces.com/contest/463/problem/C 在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得 ...

  2. Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】

    称号: 意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字.我问两个最大的大象可以吃值. 分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出 ...

  3. Codeforces Round #485 (Div. 2) E. Petr and Permutations

    Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...

  4. Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)

    Problem   Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...

  5. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  6. Codeforces Round #264 (Div. 2)

    http://codeforces.com/contest/463 这场是我人生第一场cf啊.. 悲剧处处是啊. 首先,看不懂题,完全理解不了啊.都是wa了好几次才过的 所以a和b这两sb题我做了1个 ...

  7. Codeforces Round #264 (Div. 2) C

    题目: C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  8. Codeforces Round #264 (Div. 2) E. Caisa and Tree 树上操作暴力

    http://codeforces.com/contest/463/problem/E 给出一个总节点数量为n的树,每个节点有权值,进行q次操作,每次操作有两种选项: 1. 询问节点v到root之间的 ...

  9. 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 ...

随机推荐

  1. JVM 堆参数调优 (四)

    堆参数调优 1.堆的结构 JAVA7 堆逻辑上分为:新生区.养老区.永久区:实际上堆只有新生区.养老区: Minor GC:轻量的垃圾回收:   Major GC(Full GC):重量级垃圾回收. ...

  2. mtcp的快速编译(连接)

    mtcp的快速编译 http://mos.kaist.edu/guide/config/03_build_mtcp.html 介绍DPDK中使用mtcp的文档 https://dpdksummit.c ...

  3. JVM 目录

    JVM 目录 走进 JVM Java 虚拟机规范(Oracle 官网) Java 虚拟机规范(Java SE 7 中文版) (周志明等译) 周志明,深入理解Java虚拟机[M],机械工业出版社,201 ...

  4. Permutations LT46

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

  5. Spring相关知识点

    1.注解@qualifier 只能注在属性上 作用:当一个接口有多个实现类时,用Autowired装配时,因为Autowired是按类型装配的(Resource按名称),所以多个实现类会出现冲突,这是 ...

  6. python学习 day22 (3月29日)----(生成器推导式)

    新手上路请多担待 1 2 封装 3 私有化封装 #__author : 'liuyang' #date : 2019/3/29 0029 上午 9:35 # 不想让别人看 修改 我的属性 # 源码来说 ...

  7. 简单实现java线程池

    使用多线程以及线程池的意义无需多说,要想掌握线程池,最好的方法还是自己手动去实现. 一.实现思路      (网络盗图) 二.实现代码 1.线程池类 package com.ty.thread; im ...

  8. Elastic serarch 安装

    1.安装 1.1下载最新的 elasticsearch-6.5.4.tar.gz 1.2解压 tar -zxvf elasticsearch-6.5.4.tar.gz 1.3 创建用户 elastic ...

  9. 微信小程序组件的使用

    1.在page同级目录下新建components文件夹,然后新建目录test,新建组件test 2.新建在page目录下新建目录,然后新建page页面.注意:每新建一个页面,都要修改app.json文 ...

  10. CodeForces 916B Jamie and Binary Sequence (changed after round) (贪心)

    题意:给定两个数字n,m,让你把数字 n 拆成一个长度为 m 的序列a1,a2,a3...am,并且∑2^ai = n,如果有多组,要求序列中最大的数最小,然后再相同就要求除了最大数字典序最大. 析: ...