Universal Cup Judging System

Universal Cup

Süre Sınırı: 1.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

在搜尋演算法中,我們經常會遇到以下問題:存在許多文本條目和一個關鍵字序列,你希望找到與這些關鍵字相匹配的條目。例如,條目「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$ 個條目的相關度。

範例

輸入

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