QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#3709. 最长公共子序列

統計

Bobo 在 ICPCCamp 学会了如何解决最长公共子序列问题。然而,他觉得这个问题对他来说太难了,于是他决定简化一下。

最长公共子序列问题旨在寻找一个最长的序列 $C$,使其同时是给定序列 $A$ 和 $B$ 的子序列。注意,序列 $A = (a_1, a_2, \dots, a_n)$ 仅在存在 $1 \le i_1 < i_2 < \dots < i_n \le m$ 使得 $a_1 = b_{i_1}, a_2 = b_{i_2}, \dots, a_n = b_{i_n}$ 时,才是序列 $B = (b_1, b_2, \dots, b_m)$ 的子序列。

Bobo 有一个序列 $A = (a_1, a_2, \dots, a_n)$,以及一个被划分为 $m$ 个连续段的序列 $B$。第 $i$ 段包含 $k_i$ 个元素 $b_{i,1}, b_{i,2}, \dots, b_{i,k_i}$。Bobo 可以任意次数地交换同一段内的两个元素。他想知道在进行这些交换后,$A$ 和 $B$ 的最长公共子序列的长度。

输入格式

第一行包含 3 个整数 $n, m, l$ ($1 \le n, m, l \le 3000$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le l$)。

接下来的 $m$ 行,第 $i$ 行包含一个整数 $k_i$,随后是 $k_i$ 个整数 $b_{i,1}, b_{i,2}, \dots, b_{i,k_i}$ ($k_i \ge 1, 1 \le b_{i,j} \le l, k_1 + k_2 + \dots + k_m \le 3000$)。

输出格式

输出一个整数,表示交换后最长公共子序列的长度。

样例

样例输入 1

3 2 3
1 2 3
1 1
2 3 2

样例输出 1

3

样例输入 2

2 2 3
1 3
1 1
2 3 2

样例输出 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.