• Source
    1. #include <iostream>
    2. #include <string>
    3. using namespace std;
    4. const int N = 1009;
    5. int a[N][N];
    6. int b[N][N];
    7. int main()
    8. {
    9. int n,m,p,q;
    10. int test;
    11. cin >> test;
    12. for(int t = 1; t <= test; ++t){
    13.  
    14. bool finAns = false;
    15. cin >> n >> m;
    16. for(int i = 0; i < n; ++i){
    17. string s;
    18. cin>>s;
    19. for(int j = 0; j < s.size(); ++j){
    20. a[i][j] = s[j] - '0';
    21. }
    22. }
    23. cin >> p >> q;
    24. for(int i = 0; i < p; ++i){
    25. string s;
    26. cin>>s;
    27. for(int j = 0; j < s.size(); ++j){
    28. b[i][j] = s[j] - '0';
    29. }
    30. }
    31. for(int i = 0; i < n; ++i){
    32. for(int j = 0; j < m; ++j){
    33. if( i + p > n || j + q > m){
    34. continue;
    35. }
    36. bool check = true;
    37. for(int k = 0; k < p; ++k){
    38. for(int z = 0; z < q; ++z){
    39. if( a[i + k][j + z] != b[k][z]){
    40. k = n + m;
    41. check = false;
    42. break;
    43. }
    44. }
    45. }
    46. if( check ){
    47. finAns = true;
    48. i = j = n+m;
    49. }
    50.  
    51. }
    52. }
    53. if( finAns){
    54. cout<< "YES"<<endl;
    55. } else {
    56. cout<<"NO"<<endl;
    57. }
    58. }
    59. // your code goes here
    60. return 0;
    61. }