Universal Cup Judging System

Universal Cup

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

在搜索算法中,我们经常会遇到以下问题:存在许多文本条目和一个关键词序列,你希望找到与这些关键词相匹配的条目。例如,条目 “2025 China Collegiate Programming Contest (CCPC) Jinan Regional Contest” 与关键词 “2025 CCPC Jinan” 相匹配。需要注意的是,关键词序列不需要在条目中连续出现,它只需要作为条目的子序列出现即可。

基于实际考虑,我们可以定义如下的相关度算法:从条目中选择尽可能多的互不重叠的子序列,使得每个子序列都与给定的关键词序列完全相同;此时,相关度即为选出的子序列数量。

在本题中,每个单词都可以用一个正整数表示。给定一个长度为 $m$ 的关键词序列,为了简化问题,关键词两两不同。此外,还给出了 $n$ 个条目,其中第 $i$ 个条目是一个长度为 $l_i$ 的正整数序列。你的目标是计算每个条目的相关度。

输入格式

输入的第一行包含一个整数 $m$ ($1 \le m \le 10$),表示关键词序列的长度。

第二行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$ ($1 \le b_i \le m$),表示关键词序列。保证 $b_1, b_2, \dots, b_m$ 两两不同。

第三行包含一个整数 $n$ ($1 \le n \le 100$),表示条目的数量。

接下来的 $n$ 行:第 $i$ 行首先包含一个整数 $l_i$ ($1 \le l_i \le 10^6$),表示第 $i$ 个条目的长度。接着包含 $l_i$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,l_i}$ ($1 \le a_{i,j} \le 10^6$),表示第 $i$ 个条目的内容。

保证所有条目的总长度不超过 $10^6$。

输出格式

输出 $n$ 行,其中第 $i$ 行包含一个整数,表示第 $i$ 个条目的相关度。

样例

输入 1

4
4 2 1 3
3
8 4 2 1 3 4 2 3 1
9 1 4 2 4 1 2 1 3 3
12 1 1 2 3 4 2 1 1 2 1 3 3

输出 1

1
2
1

说明

下面,我们用下标序列来表示子序列。

  • 对于第一个条目,你可以选择 $[1, 2, 3, 7]$ 作为子序列,此时 $[a_1, a_2, a_3, a_7] = [4, 2, 1, 3]$,这与关键词序列完全相同。
  • 对于第二个条目,你可以选择 $[2, 3, 5, 9]$ 和 $[4, 6, 7, 8]$ 作为子序列。注意,$[2, 3, 7, 9]$ 和 $[4, 6, 7, 9]$ 不能同时被选为子序列,因为它们的位置有重叠。

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.