You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
int T, n, m, k;
int col[26], a[6][6];
bool flag = false;
void dfs(int st)
{
if (st == -1)
{
flag = true;
return;
}
for (int i = 0; i < k; i++)
if ((st + 2) / 2 < col[i])
return;
int x = st / m, y = st % m;
for (int i = 0; i < k; i++)
if (col[i] && a[x + 1][y] != i && a[x][y + 1] != i)
{
col[a[x][y] = i]--;
dfs(st - 1);
if (flag)
return;
col[i]++;
a[x][y] = -1;
}
}
int main()
{
scanf("%d", &T);
for (int t = 1; t <= T; t++)
{
NE1(a), flag = false;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < k; i++)
scanf("%d", col + i);
dfs(n * m - 1);
printf("Case #%d:\n", t);
if (flag)
{
puts("YES");
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
printf("%d%c", a[i][j] + 1, " \n"[j == m - 1]);
}
else
puts("NO");
}
return 0;
}