Language: C++

#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll MOD = 1e9 + 7;
#define all(x)      (x).begin(), (x).end()
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())

int n, m, N;
int mp[110][110];
bool vis[110][110];
int a[10010];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool go(int x, int y){
    return x >= 0 && x < n && y >= 0 && y < m;
}
int index, num, cur, step;
void dfs(int i, int j){
    vis[i][j] = 1;
    mp[i][j] = cur;
    num--;
    step++;
    if(!num && index == N - 1){
//            cout<<i<<"aaaaaaaaaaaa"<<j<<endl;
            return;
    }
    if(num == 0){
        index ++;
        cur ++;
        num = a[index];
    }
    for(int k = 0; k < 4; ++k){
        int nx = i + dx[k];
        int ny = j + dy[k];
        if(!vis[nx][ny] && go(nx, ny)){
            dfs(nx, ny);
//            num--;
//            if(num == 0){
//                index ++;
//                cur ++;
//                num = a[index];
//            }
//            if(index == N - 1 && num == 0)return;
        }
    }
    return;
}
int main(){
    cin >> n>>m;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    index = 0; cur = 1; num = a[index], step = 0;
    dfs(0, 0);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cout << mp[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
//const int maxn = 1050;
//ll v[11][maxn];
//ll c[maxn], w[maxn];
//ll f[11][maxn];
//
//const ll inf = 12345126789123;
//int main() {
//    freopen("input.txt", "r", stdin);
//    ios_base::sync_with_stdio(0);
//    int n, m;
//    ll a, b;
//    int T;
//    cin >> T;
//    while(T--){
//    cin >> m >> n;
//    memset(v, 0, sizeof(v));
//    ll mb = inf;
//    for(int i = 1; i <= n; ++i){
//        cin>>c[i]>>w[i];
//    }
//
//    for(int i = 0; i < 11; ++i)for(int j = 0; j < maxn; ++j)f[i][j] = inf;
//    for(int k = 0; k < 11; ++k){
//    for(int i=1;i<=m;i++){
//        f[k][0] = 0;
//        for(int j=maxn;j<maxn;j++){
//                if(w[i] >= k){
//                    f[k][j]=min(f[k][j],f[k][j-w[i]+k]+c[i]);
//                }
//            }
//        }
//    }
//    if(res >= inf)cout << -1 << endl;
//    else
//    cout <<res<<endl;
//    }
//    return 0;
//}




Compiler output:
a.cc:19:5: error: 'int index' redeclared as different kind of entity
   19 | int index, num, cur, step;
      |     ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:25:22: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator=='
   25 |     if(!num && index == N - 1){
      |                ~~~~~~^~~~~~~~
a.cc:30:15: error: no post-increment operator for type
   30 |         index ++;
      |               ^~
a.cc:32:16: error: invalid types 'int [10010][<unresolved overloaded function type>]' for array subscript
   32 |         num = a[index];
      |                ^
a.cc: In function 'int main()':
a.cc:56:13: error: overloaded function with no contextual type information
   56 |     index = 0; cur = 1; num = a[index], step = 0;
      |             ^
a.cc:56:32: error: invalid types 'int [10010][<unresolved overloaded function type>]' for array subscript
   56 |     index = 0; cur = 1; num = a[index], step = 0;
      |                                ^