Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

#define DEBUG

void disp(int height, int width, int board[][width]){
	for(int i = 0; i < height; i++){
		for(int j = 0; j < width; j++){
			printf("%d ", board[i][j]);
		}
		printf("\n");
	}
	return;
}
// 2->fin
// 1->とりあえず今のところは入った
// 0->だめでした
//-1->error
int solve(int h, int w, const int height, const int width, const int n, const int a[], int board[][width], const int used[]){//usedは、中身を変えずにコピーして次へ渡す
	for(int col = 0; col < n; col++){
		if(used[col] > a[col]){
			printf("error 1 color:%d\n", col);
			return -1;
		}else if(used[col] == a[col]){
			break;
		}
		int res;
		if(used[col] == 0){//初めてこの色使うよ
			board[h][w] = col;
			if(h == height - 1 && w == width - 1){
				return 2;
			}else if(h == height - 1){
				res = solve(0, w+1, height, width, n, a, board, used);
			}else{
				res = solve(h+1, w, height, width, n, a, board, used);
			}
		}else{//もう使ったことあるから周りみるよ
			if(h > 0 && board[h-1][w] == col){
				board[h][w] = col;
				res = 1;
			}else if(w > 0 && board[h][w-1] == col){
				board[h][w] = col;
				res = 1;
			}else if(h < height - 1 && board[h+1][w] == col){
				board[h][w] = col;
				res = 1;
			}else if(w < width - 1 && board[h][w+1] == col){
				board[h][w] = col;
				res = 1;
			}else{
				break;
			}
			if(h == height - 1 && w == width - 1){
				return 2;
			}else if(h == height - 1){
				res = solve(0, w+1, height, width, n, a, board, used);
			}else{
				res = solve(h+1, w, height, width, n, a, board, used);
			}
		}
		if(res == 0){
			break;
		}else if(res == 2){
			return 2;
		}
	}
}

int main(void){
	int height, width;
	scanf("%d%d", &height, &width);
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int board[height][width];//盤面の様子、塗られている色が入る
	for(int i = 0; i < height; i++){
		for(int j = 0; j < width; j++){
			board[i][j] = 0;
		}
	}
	int used[n];//色nが今まで何回使われたか
	for(int i = 0; i < n; i++){
		used[i] = 0;
	}
	//const int height, const int width, const int n, const int a[], int board[h][w], const int used[], int h, int w)
	int ans = solve(0, 0, height, width, n, a, board, used);
	printf("%d\n\n\n", ans);
	for(int i = 0; i < height; i++){
		for(int j = 0; j < width; j++){
			printf("%d ", board[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Compiler output:
a.cc:7:51: error: use of parameter outside function body before ']' token
    7 | void disp(int height, int width, int board[][width]){
      |                                                   ^
a.cc: In function 'void disp(...)':
a.cc:8:28: error: 'height' was not declared in this scope
    8 |         for(int i = 0; i < height; i++){
      |                            ^~~~~~
a.cc:9:36: error: 'width' was not declared in this scope
    9 |                 for(int j = 0; j < width; j++){
      |                                    ^~~~~
a.cc:10:39: error: 'board' was not declared in this scope
   10 |                         printf("%d ", board[i][j]);
      |                                       ^~~~~
a.cc: At global scope:
a.cc:20:105: error: use of parameter outside function body before ']' token
   20 | int solve(int h, int w, const int height, const int width, const int n, const int a[], int board[][width], const int used[]){//usedは、中身を変えずにコピーして次へ渡す
      |                                                                                                         ^
a.cc:20:106: error: expected ')' before ',' token
   20 | int solve(int h, int w, const int height, const int width, const int n, const int a[], int board[][width], const int used[]){//usedは、中身を変えずにコピーして次へ渡す
      |          ~                                                                                               ^
      |                                                                                                          )
a.cc:20:108: error: expected unqualified-id before 'const'
   20 | int solve(int h, int w, const int height, const int width, const int n, const int a[], int board[][width], const int used[]){//usedは、中身を変えずにコピーして次へ渡す
      |                                                                                                            ^~~~~