Language: C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Puzzle {
public:
	int H, W, ulx, uly;
	vector<int> v;

	Puzzle() {};
	Puzzle(int h, int w) { reset(h, w); };
	void reset(int h, int w) {
		H = h; W = w;
		v.clear();
		v.resize(H);
	}
	int get(int i, int j) {
		return (v[i] >> (H-1-j)) & 1;
	}
	void set(int i, int j, int val) {
		if (val == 0) {
			v[i] &= ~(1 << (H-1-j));
		} else {
			v[i] |= 1 << (H-1-j);
		}
	}
	void updateUpperLeft(int val) {
		for (int i=0; i<H; ++i) {
			for (int j=0; j<W; ++j) {
				if (get(i,j) == val) {
					ulx = j, uly = i;
					return ;
				}
			}
		}
		ulx = -1, uly = -1;
	}
};

Puzzle pz, piece[10][4];
bool used[10];

string solve() {
	pz.updateUpperLeft(0);
	int x = pz.ulx, y = pz.uly;
	if (x < 0) {
		for (int i=0; i<10; ++i) {
			if ( ! used[i]) return "NO";
		}
		return "YES";
	}
	for (int i=0; i<10; ++i) {
		if (used[i]) continue;
		for (int j=0; j<4; ++j) {
			int ph = piece[i][j].H;
			int pw = piece[i][j].W;
			int sx = x - piece[i][j].ulx;
			int sy = y - piece[i][j].uly;
			bool ok = true;
			for (int k=0; k<ph && ok; ++k) {
				for (int l=0; l<pw && ok; ++l) {
					if (piece[i][j].get(k,l)
						&& (sy+k<0 || pz.H<=sy+k || sx+l<0 || pz.W<=sx+l || pz.get(sy+k,sx+l))) {
							ok = false;
						}
					}
				}
			}
			if (ok) {
				used[i] = true;
				for (int k=0; k<ph; ++k) {
					for (int l=0; l<pw; ++l) {
						if (piece[i][j].get(k,l)) {
							pz.set(sy+k,sx+l,1);
						}
					}
				}
				string ret = solve();
				used[i] = false;
				for (int k=0; k<ph; ++k) {
					for (int l=0; l<pw; ++l) {
						if (piece[i][j].get(k,l)) {
							pz.set(sy+k,sx+l,0);
						}
					}
				}
				if (ret == "YES") return ret;
			}
		}
	}
	return "NO";
}

int main() {
	int H, W;
	while (cin >> H >> W, H) {
		pz.reset(H, W);
		for (int i=0; i<H; ++i) {
			char c;
			for (int j=0; j<W; ++j) {
				cin >> c;
				pz.set(i,j,c=='#'?1:0);
			}
		}
		int n, h, w;
		cin >> n;
		for (int l=0; l<n; ++l) {
			cin >> h >> w;
			piece[l][0].reset(h, w);
			for (int i=0; i<h; ++i) {
				char c;
				for (int j=0; j<w; ++j) {
					cin >> c;
					piece[l][0].set(i,j,c=='#'?1:0);
				}
			}
			for (int i=1; i<4; ++i) {
				int ph = piece[l][i-1].W;
				int pw = piece[l][i-1].H;
				piece[l][i].reset(ph, pw);
				for (int j=0; j<ph; ++j) {
					for (int k=0; k<pw; ++k) {
						piece[l][i].set(j,k,piece[l][i-1].get(pw-1-k,j));
					}
				}
			}
			for (int i=0; i<4; ++i) piece[l][i].updateUpperLeft(1);
		}
		int p, k, t;
		cin >> p;
		for (int i=0; i<p; ++i) {
			for (int j=0; j<10; ++j) used[j] = true;
			cin >> k;
			for (int j=0; j<k; ++j) {
				cin >> t;
				used[t-1] = false;
			}
			cout << solve() << endl;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'std::string solve()':
a.cc:70:29: error: 'ok' was not declared in this scope
   70 |                         if (ok) {
      |                             ^~
a.cc:72:49: error: 'ph' was not declared in this scope; did you mean 'pz'?
   72 |                                 for (int k=0; k<ph; ++k) {
      |                                                 ^~
      |                                                 pz
a.cc:73:57: error: 'pw' was not declared in this scope; did you mean 'pz'?
   73 |                                         for (int l=0; l<pw; ++l) {
      |                                                         ^~
      |                                                         pz
a.cc:74:62: error: 'j' was not declared in this scope
   74 |                                                 if (piece[i][j].get(k,l)) {
      |                                                              ^
a.cc:75:64: error: 'sy' was not declared in this scope; did you mean 'y'?
   75 |                                                         pz.set(sy+k,sx+l,1);
      |                                                                ^~
      |                                                                y
a.cc:75:69: error: 'sx' was not declared in this scope; did you mean 'x'?
   75 |                                                         pz.set(sy+k,sx+l,1);
      |                                                                     ^~
      |                                                                     x
a.cc:81:49: error: 'ph' was not declared in this scope; did you mean 'pz'?
   81 |                                 for (int k=0; k<ph; ++k) {
      |                                                 ^~
      |                                                 pz
a.cc:82:57: error: 'pw' was not declared in this scope; did you mean 'pz'?
   82 |                                         for (int l=0; l<pw; ++l) {
      |                                                         ^~
      |                                                         pz
a.cc:83:62: error: 'j' was not declared in this scope
   83 |                                                 if (piece[i][j].get(k,l)) {
      |                                                              ^
a.cc:84:64: error: 'sy' was not declared in this scope; did you mean 'y'?
   84 |                                                         pz.set(sy+k,sx+l,0);
      |                                                                ^~
      |                                                                y
a.cc:84:69: error: 'sx' was not declared in this scope; did you mean 'x'?
   84 |                                                         pz.set(sy+k,sx+l,0);
      |                                                                     ^~
      |                                                                     x
a.cc: At global scope:
a.cc:92:9: error: expected unqualified-id before 'return'
   92 |         return "NO";
      |         ^~~~~~
a.cc:93:1: error: expected declaration before '}' token
   93 | }
      | ^
a.cc: In function 'std::string solve()':
a.cc:91:9: warning: control reaches end of non-void function [-Wreturn-type]
   91 |         }
      |         ^