[UCSD白板题] Longest Common Subsequence of Three Sequences
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的更多相关文章
- [UCSD白板题] Least Common Multiple
Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...
- [UCSD白板题] Greatest Common Divisor
Problem Introduction The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) an ...
- UVA 10405 Longest Common Subsequence (dp + LCS)
Problem C: Longest Common Subsequence Sequence 1: Sequence 2: Given two sequences of characters, pri ...
- 2017-5-14 湘潭市赛 Longest Common Subsequence 想法题
Longest Common Subsequence Accepted : Submit : Time Limit : MS Memory Limit : KB Longest Common Subs ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- LintCode Longest Common Subsequence
原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...
- Lintcode:Longest Common Subsequence 解题报告
Longest Common Subsequence 原题链接:http://lintcode.com/zh-cn/problem/longest-common-subsequence/ Given ...
- LeetCode 1143. Longest Common Subsequence
原题链接在这里:https://leetcode.com/problems/longest-common-subsequence/ 题目: Given two strings text1 and te ...
- LCS(Longest Common Subsequence 最长公共子序列)
最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...
随机推荐
- ORACLE FAQ
Q:sqlplus连接时报:ORA-12560: TNS:protocol adapter error A:1:cmd命令行上: C:\> set ORACLE_SID=orcl orcl是设置 ...
- Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- c#窗体虚线图形验证码设计
/************************窗体验证码背景图形设计及核心代码**********/ using System;using System.Collections.Generic;u ...
- Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法
报错信息: org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing ...
- iOS 定位功能的实现
1.导入框架 Xcode中添加"CoreLocation.framework" 2.导入主头文件 #import <CoreLocation/CoreLocation.h&g ...
- 使用spring配置quartz定时器
quartz是石英钟的意思,所以用这个名字来做定时器的框架名称再适合不过.一年前做项目的时候有用过这个框架,当时没有整理,今天刚好新的商城系统也需要定时器.想要达到的效果是:每天的固定时间,比如凌晨3 ...
- js jQuery中文字符串比较
先说下普通字符串(英文)比较: 一般使用双等来判断(==),如果还需要类型相同那么就用三等(===) 1. 双等(==)是完全向后兼容的,如果两个操作数类型不一致,它会在某些时候自动对操作数进行类型转 ...
- three.js 根据png生成heightmap
Three.js: render real world terrain from heightmap using open data By jos.dirksen on Tue, 07/17/2012 ...
- 金蝶K/3 Cloud 界面解析过程
服务端 目前也就是iis服务器生成Json描述返回给不同的展现端最解析. 不同的展现端,可以有Silverlight.WPF.Html5.Winform 当然还有IOS和Android端做解析展现 对 ...
- 安装pillow错误的解决方案
错误信息: ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting ...