CF10D.LCIS
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This problem differs from one which was on the online contest.
The sequence _a_1, _a_2, ..., a__n is called increasing, if a__i < a__i + 1 for i < n.
The sequence _s_1, _s_2, ..., s__k is called the subsequence of the sequence _a_1, _a_2, ..., a__n, if there exist such a set of indexes 1 ≤ _i_1 < _i_2 < ... < i__k ≤ n that a__i__j = s__j. 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.
本题与线上竞赛中的题目有所不同。
若对所有 i<n 均满足 ai<ai+1,则称序列 a1,a2,…,an 是递增的。
若存在一组下标 1≤i1<i2<⋯<ik≤n,使得 aij=sj,则称序列 s1,s2,…,sk 是序列 a1,a2,…,an 的一个子序列。换言之,序列 s 可通过对序列 a 删除若干元素而得到。
现给定两个整数序列。你需要找出它们的最长公共递增子序列(LCIS),即:既是两个序列的子序列,又是递增序列,且长度最大的那个序列。
输入格式
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.
第一行包含一个整数 n(1 ≤ n ≤ 500)—— 第一个序列的长度。
第二行包含 n 个空格分隔的整数,取值范围为 [0, 109] —— 第一个序列的元素。
第三行包含一个整数 m(1 ≤ m ≤ 500)—— 第二个序列的长度。
第四行包含 m 个空格分隔的整数,取值范围为 [0, 109] —— 第二个序列的元素。
输出格式
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.
第一行输出 k —— 最长公共上升子序列的长度。
第二行输出该子序列本身,元素之间用空格分隔。
若存在多个解,输出任意一个即可。
输入输出样例
输入#1
7 2 3 1 6 5 4 6 4 1 3 5 6
输出#1
3 3 5 6
输入#2
5 1 2 0 2 1 3 1 0 1
输出#2
2 0 1
输入解题思路,AI测评打分。不知道怎么写?