QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100 Difficulty: [show]

#2067. Evil Subsequence

الإحصائيات

这只是一个浪费你时间的不是题的题。

给定两个序列 $a_1, a_2, \dots, a_n$ 和 $b_1, b_2, \dots, b_m$。

两个序列 $(x_1, x_2, \dots, x_p)$ 和 $(y_1, y_2, \dots, y_q)$ 匹配,当且仅当 $p = q$ 且对于每一对可能的 $1 \le i, j \le p$,满足 $x_i = x_j \iff y_i = y_j$。

输出 $a_1, a_2, \dots, a_n$ 中与 $b_1, b_2, \dots, b_m$ 匹配的子序列的数量。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n \le 3000, 1 \le m \le \min(5, n)$)。

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

第三行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$ ($1 \le b_i \le m$)。

输出格式

输出一个整数:答案。

样例

输入 1

10 5
1 5 5 4 1 4 3 3 4 2
3 4 3 2 1

输出 1

20

输入 2

4 2
2 2 2 2
2 2

输出 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.