Language: C++

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, -1, 1};

int h, w;
int n;
vector<int> hy, hx;

int solve(bitset<6> used, vector<bitset<12> >& s)
{
    if(used.count() == n){
        int ret = 0;
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                if(!s[y][x])
                    ++ ret;
            }
        }
        if(ret > 7)
            return 0;
        return ret;
    }

    int ret = 0;
    for(int i=0; i<n; ++i){
        if(used[i])
            continue;

        for(int j=0; j<n; ++j){
            if(i == j || (!used[j] && j < i))
                continue;
            bitset<6> used2 = used;
            used2[i] = used2[j] = true;

            vector<bitset<12> > t = s;
            for(int y=min(hy[i],hy[j]); y<=max(hy[i],hy[j]); ++y)
                t[y][hx[i]] = true;
            for(int x=min(hx[i],hx[j]); x<=max(hx[i],hx[j]); ++x)
                t[hy[j]][x] = true;
            ret = max(ret, solve(used2, t));

            t = s;
            for(int y=min(hy[i],hy[j]); y<=max(hy[i],hy[j]); ++y)
                t[y][hx[j]] = true;
            for(int x=min(hx[i],hx[j]); x<=max(hx[i],hx[j]); ++x)
                t[hy[i]][x] = true;
            ret = max(ret, solve(used2, t));
        }

        for(int j=0; j<4; ++j){
            int y = hy[i];
            int x = hx[i];
            while(0 <= y && y < h && 0 <= x && x < w && !s[y][x]){
                y += dy[j];
                x += dx[j];
            }
            if(0 <= y && y < h && 0 <= x && x < w){
                vector<bitset<12> > t = s;
                y = hy[i];
                x = hx[i];
                while(!t[y][x]){
                    t[y][x] = true;
                    y += dy[j];
                    x += dx[j];
                }

                bitset<6> used2 = used;
                used2[i] = true;
                ret = max(ret, solve(used2, t));
            }
        }
    }

    return ret;
}

int main()
{
    for(;;){
        cin >> h >> w;
        if(h == 0)
            return 0;

        n = 0;
        hy.clear();
        hx.clear();
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                int a;
                cin >> a;
                if(a == 1){
                    ++ n;
                    hy.push_back(i);
                    hx.push_back(j);
                }
            }
        }

        cout << solve(0, vector<bitset<12> >(h)) << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:119:26: error: cannot bind non-const lvalue reference of type 'std::vector<std::bitset<12> >&' to an rvalue of type 'std::vector<std::bitset<12> >'
  119 |         cout << solve(0, vector<bitset<12> >(h)) << endl;
      |                          ^~~~~~~~~~~~~~~~~~~~~~
a.cc:29:48: note:   initializing argument 2 of 'int solve(std::bitset<6>, std::vector<std::bitset<12> >&)'
   29 | int solve(bitset<6> used, vector<bitset<12> >& s)
      |                           ~~~~~~~~~~~~~~~~~~~~~^