Problem Introduction

In this problem, your goal is to compute the length of a longest common subsequence of three sequences.

Problem Description

Task.Given three sequences \(A=(a_1,a_2,\cdots,a_n)\); \(B = (b_1, b_2,\cdots,b_m)\), and \(C=(c_1,c_2,\cdots ,c_l)\), find the length of their longest common subsequence, i.e., the largest non-negative integer \(p\) such that there exists indices
\(1 \leq i_1 < i_2 < \cdots < i_p \leq n\),\(1 \leq j_1 < j_2 < \cdots < j_p \leq m\), \(1 \leq k_1 < k_2 < \cdots < k_p \leq l\)
such that \(a_{i_1}=b_{j_1}=c_{k_1},\cdots ,a_{i_1},b_{j_p},c_{k_p}\).

Input Format.First line: \(n\). Second line: \(a_1,a_2,\cdots,a_n\). Third line: \(m\). Fourth line: \(b_1,b_2,\cdots ,b_m\). Fifth line: \(l\). Sixth line: \(c_1,c_2,\cdots,c_l\)

Constraints.\(1 \leq n,m,l \leq 100\); \(-10^9 < a_i,b_i,c_i < 10^9\)

Output Format. Output \(p\).

Sample 1.
Input:

3
1 2 3
3
2 1 3
3
1 3 5

Output:

2

Sample 2
Input:

5
8 3 2 1 7
7
8 2 1 3 8 10 7
6
6 8 3 1 4 7

Output:

3

Solution

[UCSD白板题] Longest Common Subsequence of Three Sequences的更多相关文章

  1. [UCSD白板题] Least Common Multiple

    Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...

  2. [UCSD白板题] Greatest Common Divisor

    Problem Introduction The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) an ...

  3. UVA 10405 Longest Common Subsequence (dp + LCS)

    Problem C: Longest Common Subsequence Sequence 1: Sequence 2: Given two sequences of characters, pri ...

  4. 2017-5-14 湘潭市赛 Longest Common Subsequence 想法题

    Longest Common Subsequence Accepted : Submit : Time Limit : MS Memory Limit : KB Longest Common Subs ...

  5. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  6. LintCode Longest Common Subsequence

    原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...

  7. Lintcode:Longest Common Subsequence 解题报告

    Longest Common Subsequence 原题链接:http://lintcode.com/zh-cn/problem/longest-common-subsequence/ Given ...

  8. LeetCode 1143. Longest Common Subsequence

    原题链接在这里:https://leetcode.com/problems/longest-common-subsequence/ 题目: Given two strings text1 and te ...

  9. LCS(Longest Common Subsequence 最长公共子序列)

    最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...

随机推荐

  1. 玩转UICollectionViewLayout

    前言: 实 现垂直方向的单列表来说,使用UITableView足以:若是需要构建横向滑动列表.gridView等直线型布局,则使用 UICollectionView+UICollectionViewF ...

  2. MFC对话框中显示BMP,JPG图片

    //************************************ // 方法说明:    显示JPG和GIF.BMP图片 // 参数说明:    CDC * pDC           设 ...

  3. liunx 开机流程与模块管理

    系统开机的经过可以汇整成底下的流程的: 加载 BIOS 的硬件信息与进行自我测试,并依据设定取得第一个可开机的装置: 读取并执行第一个开机装置内 MBR 的 boot Loader (亦即是 grub ...

  4. (引用)Python 元素、元组、列表、字典的区别

    转载:http://www.th7.cn/Program/Python/201407/231060.shtml 元素: 元组:tuple=('nice','to','meet','you') 列表:l ...

  5. bootstrop验证手机号

    formValidate($form,getRules(),getMessages()); function getRules(){ return { "memberViewVo.membe ...

  6. Python模块:collections

    collections模块常用的数据类型: (1)namedtuple(): #创建一个自定义的tuple对象,并且规定了tuple元素的个数,并可以用属性而不是索引来引用tuple的某个元素. fr ...

  7. My安卓知识1--SQLite数据库

    前一阵子做了一个小项目,关于android的,想记录一下学到的一些知识,做成一个小系列吧,算是对自己这一个多月来的见证.首先说明,这些知识也都是从网上各处学习来的,我自己做了一些小整理. 1.SQLi ...

  8. MongoDB的真正性能-实战百万用户一-一亿的道具

    使用情景 开始之前,我们先设定这样一个情景: 1.一百万注册用户的页游或者手游,这是不温不火的一个状态,刚好是数据量不上不下的一个情况.也刚好是传统MySql数据库性能开始吃紧的时候. 2.数据库就用 ...

  9. C# 并行编程 之 轻量级手动重置事件的使用

    目录(?)[-] 简单介绍 使用超时和取消 跨进程或AppDomain的同步   简单介绍 如果预计操作的等待的时间非常短,可以考虑使用轻量级的手动重置事件,ManualResetEventSlim. ...

  10. EXCEL文件格式不匹配,或者已经损坏,除非信任来源

    修改注册表解决: .打开注册表编辑器 方法:开始 -> 运行 -> 输入regedit -> 确定 .找到注册表子项 HKEY_CURRENT_USER\Software\Micro ...