LCIS(翻译)

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---是这个最长共同升序子序列的长度。在第二行输出这个子序列本身。用空格分隔这些元素。如果有多个答案,那么输出任意一个即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值