#include <iostream> (720)#include <cstdio> #include <cmath> (808)#include <cstring> using namespace std; typedef long long LL; const int maxn = 5010; int t, n, m, c, flag = 0; int l[maxn], cnt[maxn], mp[8][8]; void dfs(int x, int y) { //printf("%d %d\n", x, y); if (x == n && y == m + 1) { flag = 1; return; } for (int i = 0; i < c; i++) { if (flag == 1) break; if (i != mp[x - 1][y] && i != mp[x][y - 1] && cnt[i] < l[i]) { mp[x][y] = i; cnt[i]++; if (x != n && y == m) dfs(x + 1, 1); else dfs(x, y + 1); cnt[i]--; mp[x][y] = -1; } } } int main() { scanf("%d", &t); while (t--) { memset(mp, -1, sizeof mp); flag = 0; scanf("%d %d %d", &n, &m, &c); for (int i = 0; i < c; i++) { scanf("%d", &l[i]); } dfs(1, 1); printf("%s\n", flag == 1?"YES":"NO"); } return 0; }
点赞 评论

相关推荐

投递CVTE等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客企业服务