Language: C++

#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int table[10][10],num;
};


int W,H,ans;
int first_table[10][10],max_size[10][10];

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
	else{
		return false;
	}
}

void copyTable(Info& to,int from[10][10],int base_row){

	for(int row = base_row; row < H; row++){
		for(int col = 0; col < W; col++)to.table[row][col] = from[row][col];
	}
}

void recursive(Info info,int base_row,int base_col){

	if(info.num == ans)return;

	if(base_row == H){ //??¨???????????????????????§?????£?????´???
		ans = min(ans,info.num);
		return;
	}

	//printf("ans:%d\n",ans);

	Info next_info;

	if(info.table[base_row][base_col] == -1){ //????????????????¶???????????????§????????´???

		copyTable(next_info,info.table,base_row);
		next_info.num = info.num;

		//???????????????????????????????§?
		if(base_col == W-1){
			recursive(next_info,base_row+1,0);
		}else{
			recursive(next_info,base_row,base_col+1);
		}
		return;
	}

	//?°?????????¨???1???????????°??????????????????????????????????????????[[????????§??????????????????????????????????????]]
	int new_num = 0;
	for(int i = 0; i < max_size[base_row][base_col]; i++){
		for(int k = 0; k < max_size[base_row][base_col]; k++){
			if(info.table[base_row+i][base_col+k] == 0){
				new_num++;
			}
		}
	}

	if(new_num == 0){ //??°?????????????????????????????????

		copyTable(next_info,info.table,base_row);
		next_info.num = info.num;

		//???????????????????????????????§?
		if(base_col == W-1){
			recursive(next_info,base_row+1,0);
		}else{
			recursive(next_info,base_row,base_col+1);
		}
	}else{

		//????????????(?????????????????¢???????????????????????´?????????):???dfs??§??°????°????????????????????????±???????????????
		if(info.table[base_row][base_col] != 0){
			Info next_not;

			copyTable(next_not,info.table,base_row);
			next_not.num = info.num;

			int must_add = 0;
			bool FLG = false;
			//?°?????????¨??????????????§??????????????????????????°????¨????
			for(int row = base_row; row < H; row++){
				for(int col = 0; col < W; col++){
					if(next_not.table[row][col] == 0 && first_table[row][col] == 1){
						must_add++;
					}else if(next_not.table[row][col] == 0 && first_table[row][col] > 1){
						FLG = true;
					}
				}
			}

			if(FLG)must_add++;

			if(next_not.num+must_add < ans){
				if(base_col == W-1){
					recursive(next_not,base_row+1,0);
				}else{
					recursive(next_not,base_row,base_col+1);
				}
			}
		}

		copyTable(next_info,info.table);
		next_info.num = info.num+1;

		//????????????????????????
		for(int i = 0; i < max_size[base_row][base_col]; i++){
			for(int k = 0; k < max_size[base_row][base_col]; k++){
				next_info.table[base_row+i][base_col+k]++;
			}
		}

		int must_add = 0;
		bool FLG = false;
		//?°?????????¨??????????????§??????????????????????????°????¨????
		for(int row = base_row; row < H; row++){
			for(int col = 0; col < W; col++){
				if(next_info.table[row][col] == 0 && first_table[row][col] == 1){
					must_add++;
				}else if(next_info.table[row][col] == 0 && first_table[row][col] > 1){
					FLG = true;
				}
			}
		}

		if(FLG)must_add++;

		if(next_info.num+must_add < ans){
			if(base_col == W-1){
				recursive(next_info,base_row+1,0);
			}else{
				recursive(next_info,base_row,base_col+1);
			}
		}
	}
}


void func(){

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%d",&first_table[row][col]);
			first_table[row][col] -= 1;
		}
	}

	bool FLG;
	int size;
	//?????????????????????????????§????????????????±???????
	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(first_table[row][col] == -1){
				max_size[row][col] = 0;
			}else{
				size = 1;

				FLG = true;

				while(true){
					for(int i = 0; i < size; i++){
						for(int k = 0; k < size; k++){
							if(rangeCheck(row+i,col+k) == false || first_table[row+i][col+k] == -1){
								FLG = false;
								break;
							}
						}
						if(!FLG)break;
					}
					if(!FLG){
						size -= 1;
						break;
					}
					size++;
				}

				max_size[row][col] = size;

				//1??????????????????????????????????????????????????????????????????????????§?????????????????§??????????????´?????????????????????????????????
				for(int i = 0; i < size; i++){
					for(int k = 0; k < size; k++){
						first_table[row+i][col+k]++;
					}
				}
			}
		}
	}

	Info start;
	start.num = 0;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(first_table[row][col] == -1){
				start.table[row][col] = -1;
			}else{
				start.table[row][col] = 0;
			}
		}
	}

	ans = BIG_NUM;

	recursive(start,0,0);

	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		func();
	}

	return 0;
}

Compiler output:
a.cc: In function 'void recursive(Info, int, int)':
a.cc:124:26: error: too few arguments to function 'void copyTable(Info&, int (*)[10], int)'
  124 |                 copyTable(next_info,info.table);
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:36:6: note: declared here
   36 | void copyTable(Info& to,int from[10][10],int base_row){
      |      ^~~~~~~~~