QOJ.ac

QOJ

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

#2316. 贪心字符串匹配

Estadísticas

给定一个长字符串和一组关键词,你需要找出这些关键词在给定字符串中的非重叠匹配。虽然有几种动态规划算法可以最大化匹配字符的总数,但考虑到效率,你不需要在这一题中使用它们。

相反,你需要实现一个贪心算法:从左到右,尝试从每个未匹配的字符开始匹配最长的关键词。最后,输出匹配字符的总数。

输入格式

第一行包含长字符串 $S$ ($1 \le |S| \le 10^5$)。第二行包含一个整数 $N$,即关键词的数量 ($1 \le N \le 10^4$)。接下来的 $N$ 行中,每行包含一个关键词。这些关键词的长度均不超过 $100$。所有字符串仅由小写英文字母组成。

输出格式

对于每个测试用例,输出一行匹配字符的总数。

样例

样例输入 1

thisicpccontestissooocoooool
3
icpc
so
cool

样例输出 1

6

样例输入 2

thisisanoverlapcase
4
this
isis
is
san

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