#C10209. Matrix Word Search
Matrix Word Search
Matrix Word Search
You are given a matrix (grid) of characters with dimensions (R \times C) and a target word. Your task is to determine whether the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are those horizontally or vertically neighboring. Note that the same cell cannot be used more than once in constructing the word.
For example, given the grid:
abce
sfcs
adee
and the word see, the answer is YES because the sequence of letters exists in the grid.
Write a program that reads the input from standard input (stdin) and writes the result to standard output (stdout).
inputFormat
Input is given via stdin. The first line contains two integers (R) and (C) denoting the number of rows and columns respectively. The following (R) lines each contain a string of length (C) representing the grid. The last line contains the target word.
outputFormat
Output a single line containing either YES
if the word exists in the grid or NO
if it does not.## sample
3 4
abce
sfcs
adee
see
YES