QOJ.ac

QOJ

حد الوقت: 6 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#3613. 变态单词搜索

الإحصائيات

你可能熟悉常规的单词搜索游戏,即在一个字母网格中寻找给定的单词。单词可以水平、垂直或对角线方向(包括这些方向的逆向)呈直线排列。例如,下面是一个字母网格:

图 1:单词搜索网格

单词 “JAVA” 可以从右下角沿对角线向上找到。

在“扭曲单词搜索”(kinky word search)中,拼写单词的路径可以有一个或多个“扭曲点”(kinks)——即路径改变方向的位置。例如,在给定的网格中,你可以拼写出带有 3 个扭曲点的单词 “PYTHON”(在 T、H 和 O 处各有一个):

图 2:单词 “PYTHON” 的一种扭曲拼写方式

增加扭曲点允许字母被重复使用——单词 “CPLUSPLUS” 可以在网格的右上角找到(带有 5 个扭曲点)。然而,你不能连续两次停留在同一个字母上,因此你无法在这个网格中拼写出单词 “HASKELL”(尽管你可以找到至少 11 种更常见的编程语言)。你的任务是判断在给定的网格中,是否可以用特定数量的扭曲点拼写出某个单词。

输入格式

输入的第一行包含两个正整数 $r$ 和 $c$ ($r, c \leq 10$),表示网格的行数和列数。接下来是 $r$ 行,每行包含 $c$ 个大写字母。字母之间由空格分隔。网格之后是两行:第一行是一个整数 $k$,表示扭曲点的数量。第二行包含一个要查找的大写单词,最大长度为 100。

输出格式

如果可以在给定的网格中恰好用 $k$ 个扭曲点拼写出该单词,则输出 Yes,否则输出 No。

样例

样例输入 1

5 5
L M E L C
C A K U P
D O V S Y
R N L A T
P G O H J
0
JAVA

样例输出 1

Yes

样例输入 2

5 5
L M E L C
C A K U P
D O V S Y
R N L A T
P G O H J
3
PYTHON

样例输出 2

Yes

样例输入 3

5 5
L M E L C
C A K U P
D O V S Y
R N L A T
P G O H J
4
PYTHON

样例输出 3

No

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.