2022.2.6
题目网址:
https://codeforces.com/contest/10/problem/D
原题:
LCIS
1000ms 262144K
描述:
This problem differs from one which was on the online contest.
The sequence a1,?a2,?...,?an is called increasing, if ai?<?ai?+?1 for i?<?n.
The sequence s1,?s2,?...,?sk is called the subsequence of the sequence a1,?a2,?...,?an, if there exist such a set of indexes 1?≤?i1?<?i2?<?...?<?ik?≤?n that aij?=?sj. In other words, the sequence s can be derived from the sequence a by crossing out some elements.
You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.
输入:
The first line contains an integer n (1?≤?n?≤?500) — the length of the first sequence. The second line contains n space-separated integers from the range [0,?109] — elements of the first sequence. The third line contains an integer m (1?≤?m?≤?500) — the length of the second sequence. The fourth line contains m space-separated integers from the range [0,?109] — elements of the second sequence.
输出:
In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.
翻译:
描述:
这个问题不同于网上的任何一场比赛的问题。
有一个a1,a2,...,an的升序序列,对于i<n来说ai<ai+1。
序列s1,s2,...,sk是序列a1,a2,...,an的一个子序列,如果存在这样一套索引1<=i1<i2<...<ik<=n有aij=sj。换句话说,序列s能通过删去序列a中的一些元素得到。
你被给了两个整数序列。你要去找到它们的最长的共同的升序序列,一个升序的最长子序列。
输入:
第一行包含一个整数n(1<=n<=500)---是第一个序列的长度。第二行包含n个以空格分开的整数,范围是【0,109】---是第一个序列的元素。第三行包含一个整数m(1<=m<=500)---是第二个序列的长度。第四行包含m个以空格分开的整数,范围是【0,109】---是第二个序列的元素。
输出:
第一行输出k---是这个最长共同升序子序列的长度。在第二行输出这个子序列本身。用空格分隔这些元素。如果有多个答案,那么输出任意一个即可。