QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#3942. 音乐会上的键盘

Estadísticas

Olav 有一些电子琴,他想演奏一首曲子。不幸的是,Olav 的所有电子琴都坏了,每台琴只能演奏其中的一部分音符。通过切换他正在使用的乐器,他将能够演奏整首曲子,但搬动键盘很麻烦,所以他想尽量减少切换的次数。你能帮 Olav 计算出演奏整首曲子所需的最少键盘切换次数吗?

CC-BY 2.0, Daniel Spils via Flickr

输入格式

第一行包含两个空格分隔的整数:$n$ ($1 \le n \le 1\,000$),表示乐器的数量;$m$ ($1 \le m \le 1\,000$),表示曲子中音符的数量。接下来有 $n$ 行,每行首先是一个整数 $k_i$ ($1 \le k_i \le 1\,000$),表示第 $i$ 台乐器可以演奏的音符数量,随后是 $k_i$ 个两两不同的整数 $\ell_1, \ell_2, \dots, \ell_{k_i}$,表示第 $i$ 台乐器可以演奏的音符 ($1 \le \ell_j \le 1\,000$)。最后一行包含 $m$ 个空格分隔的整数,表示按顺序排列的曲子音符。

输出格式

Olav 在演奏曲子期间需要切换乐器的最少次数。

样例

样例输入 1

2 10
2 1 2
2 2 3
1 2 1 2 3 3 2 3 1 3

样例输出 1

3

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.