全部评论
#include <iostream> #include <cstdio> #include <cmath> #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; }
第二题回溯只有给的用例能通过,,应该是超时了,忘了剪枝。
我第一题也是用的中位数,但是只对了80%的测试😂
两题都是没做出来 好难
感觉是回溯,没写完
好奇第一题怎么做。。第一次做国内公司的面试,感觉是简单的数学但就是没想出来。
相关推荐
2025-11-18 20:04
泉州职业技术大学 算法工程师
专业嗎喽:个人信息名字太大,合到电话邮箱那一栏就行,有党员写过党,剩下其他全删,站空太大了
把实习经历丰富,放最前面,然后是个人评价,技能之类的,然后是学校信息。项目经历最后面,可以就选一个自己擅长的。
现在是学校不是92就扣分的,没必要放前面。
然后现在看重实习经历>竞赛经历(校园经历)>课程项目经历 点赞 评论 收藏
分享
2025-11-12 16:07
郑州轻工业大学 UI设计师 点赞 评论 收藏
分享
