#P9122. Stamp Painting
Stamp Painting
Stamp Painting
A stamp painting is a black and white painting on an \(N \times N\) canvas, where certain cells are inked while others are blank. It is represented by an \(N \times N\) grid of characters. The \(i\)-th entry of the \(j\)-th column is *
if that square is inked and .
otherwise.
Bessie has a stamp painting in mind that she wishes to create. Farmer John lends her a single \(K \times K\) stamp (with \(1 \le K \le N\)) and an initially blank \(N \times N\) canvas. Bessie can repeatedly perform the following operation:
- Rotate the stamp clockwise by \(90^\circ\) any number of times.
- Stamp the canvas by choosing integers \(i,j\) with \(1 \le i,j \le N-K+1\). For every \(1 \le i' , j' \le K\), the canvas cell \((i+i'-1, j+j'-1)\) is painted black if the stamp (in its current rotation) has ink on cell \((i',j')\).
Once a canvas cell is painted black, it remains black. Your task is to determine whether it is possible for Bessie to create her desired stamp painting using the given stamp.
The input consists of multiple test cases. In each test case:
- The first line contains two integers \(N\) and \(K\).
- The next \(N\) lines each contain a string of \(N\) characters representing the desired canvas (each character is either
*
or.
). - The next \(K\) lines each contain a string of \(K\) characters representing the stamp (each character is either
*
or.
).
For each test case, output YES
if it is possible for Bessie to create the desired painting, or NO
otherwise.
Note: The stamp may be rotated by \(90^\circ\), \(180^\circ\), or \(270^\circ\) before stamping.
inputFormat
The first line contains an integer \(T\) (\(1 \le T \le 100\)), the number of test cases.
For each test case, the first line contains two space-separated integers \(N\) and \(K\) (\(1 \le K \le N \le 20\)).
The next \(N\) lines each contain a string of length \(N\) representing the desired painting. Each character is either *
or .
.
The next \(K\) lines each contain a string of length \(K\) representing the stamp pattern. Each character is either *
or .
.
outputFormat
For each test case, output a single line containing YES
if it is possible to obtain the desired stamp painting, or NO
otherwise.
sample
3
3 2
**.
***
.**
**
.*
3 3
***
***
***
***
*.*
***
3 2
*..
***
..*
**
**
YES
YES
NO
</p>