Language: C++

#include<bits/stdc++.h>

using namespace std;


int p[10][10], s[10][10];
vector< vector< int > > st;
map< vector< int >, int > dp;
int W, H;

int dfs(int x, int y)
{
  if(dp.count(st)) return (dp[st]);
  if(y == H) return (0);
  if(x == W) return (dfs(0, y + 1));
  if(p[y][x] == 0) return (dfs(x + 1, y));
  int ret = 1 << 30;
  if(st[y][x] == 0) ret = min(ret, dfs(x + 1, y));
  vector< pair< int, int > > beet;
  for(int i = 0; i < s[y][x]; i++) {
    for(int j = 0; j < s[y][x]; j++) {
      if(st[y + i][x + j] == 1) {
        beet.emplace_back(y + i, x + j);
        st[y + i][x + j] = 0;
      }
    }
  }
  if(beet.size()) {
    ret = min(ret, dfs(x + 1, y) + 1);
    for(auto &p : beet) st[p.first][p.second] = 1;
  }
  return (dp[st] = ret);
}

int main()
{
  while(cin >> W >> H, W) {
    st.resize(H);
    for(int i = 0; i < H; i++) {
      st[i].resize(W);
      for(int j = 0; j < W; j++) {
        cin >> p[i][j];
        st[i][j] = p[i][j];
      }
    }
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        for(int k = min(H - i, W - j); k >= 1; k--) {
          bool flag = true;
          for(int l = 0; l < k; l++) {
            for(int m = 0; m < k; m++) flag &= p[i + l][j + m];
          }
          if(flag) {
            s[i][j] = k;
            break;
          }
        }
      }
    }
    cout << dfs(0, 0) << endl;
  }
}

Compiler output:
a.cc: In function 'int dfs(int, int)':
a.cc:13:14: error: no matching function for call to 'std::map<std::vector<int>, int>::count(std::vector<std::vector<int> >&)'
   13 |   if(dp.count(st)) return (dp[st]);
      |      ~~~~~~~~^~~~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:1270:9: note: candidate: 'template<class _Kt> decltype (((const std::map<_Key, _Tp, _Compare, _Alloc>*)this)->std::map<_Key, _Tp, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::map<_Key, _Tp, _Compare, _Alloc>::count(const _Kt&) const [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >]'
 1270 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |         ^~~~~
/usr/include/c++/14/bits/stl_map.h:1270:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_map.h: In substitution of 'template<class _Kt> decltype (((const std::map<std::vector<int>, int>*)this)->std::map<std::vector<int>, int>::_M_t.std::_Rb_tree<std::vector<int>, std::pair<const std::vector<int>, int>, std::_Select1st<std::pair<const std::vector<int>, int> >, std::less<std::vector<int> >, std::allocator<std::pair<const std::vector<int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::map<std::vector<int>, int>::count(const _Kt&) const [with _Kt = std::vector<std::vector<int> >]':
a.cc:13:14:   required from here
   13 |   if(dp.count(st)) return (dp[st]);
      |      ~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_map.h:1270:65: error: no matching function for call to 'std::_Rb_tree<std::vector<int>, std::pair<const std::vector<int>, int>, std::_Select1st<std::pair<const std::vector<int>, int> >, std::less<std::vector<int> >, std::allocator<std::pair<const std::vector<int>, int> > >::_M_count_tr(const std::vector<std::vector<int> >&) const'
 1270 |         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
      |                                                 ~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_tree.h:1311:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Req = _Kt; _Key = std::vector<int>; _Val = std::pair<const std::vector<int>, int>; _KeyOfValue = std::_Select1st<std::pair<const std::vector<int>, int> >; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >]'
 1311 |         _M_count_tr(const _Kt& __k) const
      |         ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1311:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/stl_function.h: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<std::vector<int> >; _SfinaeType = std::vector<std::vector<int> >]':
/usr/include/c++/14/bits/stl_tree.h:1309:9:   required by substitution of 'template<class _Kt> decltype (((const std::map<std::vector<int>, int>*)this)->std::map<std::vector<int>, int>::_M_t.std::_Rb_tree<std::vector<int>, std::pair<const std::vector<int>, int>, std::_Select1st<std::pair<const std::vector<int>, int> >, std::less<std::vector<int> >, std::allocator<std::pair<const std::vector<int>, int> > >::_M_count_tr<_Kt, _Req>(__x)) std::map<std::vector<int>, int>::count(const _Kt&) const [with _Kt = std::vector<std::vector<int> >]'
 1309 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:13:14:   required from here
   13 |   if(dp.count(st)) return (dp[st]);
      |      ~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<std::vector<int> >, std::vector<std::vector<int> >, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1264:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::size_type std::map<_Key, _Tp, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >; size_type = long unsigned int; key_type = std::vector<int>]'
 1264 |       count(const key_type& __x) const
      |       ^~~~~
/usr/include/c++/14/bits/stl_map.h:1264:29: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'const std::map<std::vector<int>, int>::key_type&' {aka 'const std::vector<int>&'}
 1264 |       count(const key_type& __x) const
      |             ~~~~~~~~~~~~~~~~^~~
a.cc:13:30: error: no match for 'operator[]' (operand types are 'std::map<std::vector<int>, int>' and 'std::vector<std::vector<int> >')
   13 |   if(dp.count(st)) return (dp[st]);
      |                              ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >; mapped_type = int; key_type = std::vector<int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'const std::map<std::vector<int>, int>::key_type&' {aka 'const std::vector<int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >; mapped_type = int; key_type = std::vector<int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'std::map<std::vector<int>, int>::key_type&&' {aka 'std::vector<int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:32:13: error: no match for 'operator[]' (operand types are 'std::map<std::vector<int>, int>' and 'std::vector<std::vector<int> >')
   32 |   return (dp[st] = ret);
      |             ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >; mapped_type = int; key_type = std::vector<int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'const std::map<std::vector<int>, int>::key_type&' {aka 'const std::vector<int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::vector<int>; _Tp = int; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::pair<const std::vector<int>, int> >; mapped_type = int; key_type = std::vector<int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'std::map<std::vector<int>, int>::key_type&&' {aka 'std::vector<int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~