QOJ.ac

QOJ

حد الوقت: 10 s حد الذاكرة: 16 MB مجموع النقاط: 100

#2622. Gross LCS

الإحصائيات

令 $\text{LCS}(A, B)$ 表示整数序列 $A = \langle a_1, a_2, \dots, a_n \rangle$ 和 $B = \langle b_1, b_2, \dots, b_m \rangle$ 的最长公共子序列的长度。

对于整数 $x$,令 $A + x$ 表示序列 $\langle a_1 + x, a_2 + x, \dots, a_n + x \rangle$。

给定两个整数序列 $A$ 和 $B$,求所有整数 $x$(从 $-10^{100}$ 到 $10^{100}$)的 $\text{LCS}(A + x, B)$ 之和。

注意:内存限制非常小,所有语言的内存限制均为 16 MB。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 4000$)。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($-10^8 \le a_i \le 10^8$)。 第三行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$ ($-10^8 \le b_i \le 10^8$)。

输出格式

输出所有整数 $x$(从 $-10^{100}$ 到 $10^{100}$)的 $\text{LCS}(A + x, B)$ 之和。

样例

样例输入 1

3 4
5 5 8
3 6 3 6

样例输出 1

6

说明

如果整数序列 $P$ 可以通过从整数序列 $Q$ 中删除若干个(可能为零个或全部)元素得到,则称 $P$ 是 $Q$ 的子序列。序列 $A$ 和 $B$ 的最长公共子序列是既是 $A$ 的子序列又是 $B$ 的子序列的最长序列。

在样例测试中: $\text{LCS}(A - 5, B) = \text{LCS}(\langle 0, 0, 3 \rangle, \langle 3, 6, 3, 6 \rangle) = 1$; $\text{LCS}(A - 2, B) = \text{LCS}(\langle 3, 3, 6 \rangle, \langle 3, 6, 3, 6 \rangle) = 3$; $\text{LCS}(A + 1, B) = \text{LCS}(\langle 6, 6, 9 \rangle, \langle 3, 6, 3, 6 \rangle) = 2$; 对于任何 $x \notin \{-5, -2, 1\}$,$\text{LCS}(A + x, B) = 0$。

因此答案为 $1 + 3 + 2 = 6$。

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.