luogu#P9122. [USACO23FEB] Stamp Grid B

[USACO23FEB] Stamp Grid B

题目描述

A stamp painting is a black and white painting on an N×NN \times N canvas, where certain cells are inked while others are blank. It can be described by an N×NN \times N array of characters (1N20)(1 \le N \le 20). The ii-th entry of the jj-th column of the array is equal to * if the canvas contains ink at that square and . otherwise.

Bessie has a stamp painting that she would like to create, so Farmer John has lent her a single K×K(1KN)K \times K(1 \le K \le N) stamp to do this and an empty N×NN \times N canvas. Bessie can repeatedly rotate the stamp clockwise by 9090^{\circ} and stamp anywhere on the grid as long as the stamp is entirely inside the grid. Formally, to stamp, Bessie chooses integers i,ji,j such that i[1,NK+1]i \in [1,N−K+1] and j[1,NK+1]j \in [1,N−K+1]; for each (i,j)(i^{\prime},j^{\prime}) such that 1i,jK1 \le i^{\prime},j^{\prime} \le K, canvas cell (i+i1,j+j1)(i+i^{\prime}−1,j+j^{\prime}−1) is painted black if the stamp has ink at (i,j)(i^{\prime},j^{\prime}). Bessie can rotate the stamp at any time between stampings. Once a canvas cell is painted black, it remains black.

Farmer John is wondering whether it's possible for Bessie to create her desired stamp painting with his stamp. For each of T(1T100)T(1 \le T \le 100) test cases, help Farmer John answer this question.

输入格式

The first line of input contains TT, the number of test cases.

Each test case starts with an integer NN followed by NN lines, each containing a string of *s and .s, representing Bessie's desired stamp painting. The next line contains KK and is followed by KK lines, each containing a string of *s and .s, representing Farmer John's stamp.

Consecutive test cases are separated by newlines.

输出格式

For each test case, output YES or NO on separate lines.

题目大意

邮票画是在 N×NN \times N 画布上的黑白画,其中某些单元被涂上墨水,而其他单元则是空白。它可以用一个 N×NN \times N 的字符数组来描述 (1N20)(1 \le N \le 20)。如果画布在该方格含有墨水,则数组中第ii行的第jj列为 *,否则等于 .

Bessie有一幅邮票画,她想创作,所以农夫John借给她一张 K×K(1KN)K \times K(1 \le K \le N) 的邮票来做,还有一张空的 N×NN \times N 的帆布。Bessie可以重复地将邮票顺时针旋转9090^{\circ} 。并在网格上的任何地方涂墨,只要涂墨的地方完全在网格内。为了涂墨,Bessie选择整数 i,ji,j ,使 i[1,NK+1]i \in [1,N−K+1] and j[1,NK+1]j \in [1,N−K+1];对于每一个 (i,j)(i^{\prime},j^{\prime}) 使 1i,jK1 \le i^{\prime},j^{\prime} \le K

Bessie可以在两次盖章之间的任何时候旋转印章。一旦邮票画被涂成黑色,它就一直是黑色的。

农民John想知道Bessie是否有可能用他的邮票创造出她想要的邮票画。对于 T(1T100)T(1 \le T \le 100) 的每一个测试案例,帮助农夫John回答这个问题。

4

2
**
*.
1
*

3
.**
.**
***
2
.*
**

3
...
.*.
...
3
.*.
...
...

3
**.
.**
..*
2
.*
*.
YES
YES
NO
YES

提示

Explanation for Sample 1

In the first test case, Bessie can perform the following sequence of stampings:

  1. Stamp at (1,1)(1,1)
  2. Stamp at (1,2)(1,2)
  3. Stamp at (2,1)(2,1)

In the second test case, Bessie can perform the following sequence of stampings:

  1. Stamp at (2,2)(2,2)
  2. Stamp at (2,1)(2,1)
  3. Rotate 9090^{\circ}
  4. Rotate 9090^{\circ}
  5. Stamp at (1,2)(1,2)

In the third test case, it is impossible to paint the middle cell.

In the fourth test case, Bessie can perform the following sequence of stampings:

  1. Rotate 9090^{\circ}
  2. Stamp at (1,1)(1,1)
  3. Stamp at (1,2)(1,2)
  4. Stamp at (2,2)(2,2)