Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long LL;
typedef pair<int, LL> Result;
class ParseError{};
struct Parser{
    Result expr(string s, int p){
        Result r = term(s, p);
        while(s[r.first] == '+' || s[r.first] == '-'){
            Result t = term(s, r.first + 1);
            if(s[r.first] == '+'){
                r.second += t.second;
            }else{
                r.second -= t.second;
            }
            r.first = t.first;
        }
        return r;
    }
    Result term(string s, int p){
        Result r = factor(s, p);
        while(s[r.first] == '*' || s[r.first] == '/'){
            Result t = factor(s, r.first + 1);
            if(s[r.first] == '*'){
                r.second *= t.second;
            }else{
                if(t.second == 0) throw ParseError();
                r.second /= t.second;
            }
            r.first = t.first;
        }
        return r;
    }
    Result factor(string s, int p){
        if(s[p] == '0'){
            if(isdigit(s[p + 1])) throw ParseError();
            return Result(p + 1, 0);
        }else if(isdigit(s[p])){
            LL num = 0;
            while(isdigit(s[p])){
                num = num * 10 + s[p++] - '0';
            }
            return Result(p, num);
        }else{
            throw ParseError();
        }
    }
};
LL parse(string s){
    LL res = Parser().expr(s, 0).second;
    return res;
}
char select[10];
bool used[10];
int H, W, L;
bool dfs(int k, vector<char>& vc, vector<string> check[10]){
    if(k == L) return true;
    REP(i, vc.size()) if(!used[i]){
        select[k] = vc[i];
        used[i] = true;
        for(auto s : check[k]){
            string s1, s2;
            for(auto& c : s) {
                if(islower(c)){
                    c = select[ c - 'a' ];
                }
                if(c == '='){
                    if(s2.size() > 0) goto NEXT;
                    swap(s1, s2);
                }else{
                    s1 += c;
                }
            }
            try{
                if(parse(s1) != parse(s2)) goto NEXT;
            }catch(ParseError e){
                goto NEXT;
            }
        }
        if(dfs(k + 1, vc, check)) return true;
        NEXT:
        used[i] = false;
    }
    return false;
}
int main(){
    while(cin >> H >> W && H){
        vector<string> grid(H);
        REP(i, H) cin >> grid[i];

        vector<int> bx, by;
        REP(y, H) REP(x, W) if(grid[y][x] == '.') { bx.push_back(x); by.push_back(y); grid[y][x] = bx.size() - 1 + 'a';}


        cin >> L;
        vector<char> vc(L);
        for(auto& c : vc) cin >> c;
        sort(vc.begin(), vc.end());

        vector<string> check[10];

        REP(y, H) REP(x, W) if(grid[y][x] != '#'){
            if(y < H - 1 && (y == 0 || grid[y - 1][x] == '#') && grid[y + 1][x] != '#'){
                string s;
                for(int dy = 0; y + dy < H && grid[y + dy][x] != '#'; dy++){
                    s += grid[y + dy][x];
                }
                int maxk = 0;
                for(auto c : s) if(islower(c)) maxk = max(maxk, c - 'a');
                check[maxk].push_back(s);
            }
            if(x < W - 1 && (x == 0 || grid[y][x - 1] == '#') && grid[y][x + 1] != '#'){
                string s;
                for(int dx = 0; x + dx < W && grid[y][x + dx] != '#'; dx++){
                    s += grid[y][x + dx];
                }
                int maxk = 0;
                for(auto c : s) if(islower(c)) maxk = max(maxk, c - 'a');
                check[maxk].push_back(s);
            }
        }

        bool ans = dfs(0, vc, check);

        if(ans) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Compiler output:
a.cc:55:15: error: 'char select [10]' redeclared as different kind of entity
   55 | char select[10];
      |               ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/sys/select.h:102:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
  102 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
a.cc: In function 'bool dfs(int, std::vector<char>&, std::vector<std::__cxx11::basic_string<char> >*)':
a.cc:61:17: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |         select[k] = vc[i];
      |                 ^
a.cc:61:19: error: assignment of read-only location '*(select + ((sizetype)k))'
   61 |         select[k] = vc[i];
a.cc:67:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   67 |                     c = select[ c - 'a' ];
      |                                         ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:67:41: error: invalid conversion from 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to 'char' [-fpermissive]
   67 |                     c = select[ c - 'a' ];
      |                         ~~~~~~~~~~~~~~~~^
      |                                         |
      |                                         int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)