当前位置:网站首页>691. 立方体IV
691. 立方体IV
2022-08-05 06:42:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
文章目录
691. 立方体IV
题意
Vincenzo 决定制作立方体 IV,但所有预算只够制作一个正方形迷宫。
它是一个完美的迷宫,每个房间都呈正方形,并具有 4 扇门(四个边一边 1 个)。
每个房间里都有一个号码。
一个人只有在下一个房间的号码比当前房间的号码大 1 的情况下,才能从当前房间移动到下一个房间。
现在,Vincenzo 为所有房间分配了唯一的号码(1,2,3,…S2)然后将 S2 个人放在了迷宫中,每个房间 1 个,其中 S 是迷宫的边长
能够移动次数最多的人将获胜。
弄清楚谁将成为赢家,以及他将能够到达的房间数量。思路
记忆化搜索板子题
代码
/* * @Author: NEFU AB-IN * @Date: 2022-08-04 15:03:57 * @FilePath: \Acwing\691\691.cpp * @LastEditTime: 2022-08-04 15:56:20 */ #include <bits/stdc++.h> using namespace std; #define int long long #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int INF = INT_MAX; const int N = 1e6 + 10; void solve(int T) { int n; cin >> n; vector<vector<int>> g(n + 10, vector<int>(n + 10)), f(n + 10, vector<int>(n + 10, -1)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> g[i][j]; } } int d = 0, r = n * n; function<int(int, int)> dp = [&](int x, int y) { if (f[x][y] != -1) return f[x][y]; // 如果遍历到了直接返回 f[x][y] = 1; // 初始化走一步 vector<PII> dir = { { -1, 0}, { 0, -1}, { 1, 0}, { 0, 1}}; for (int i = 0; i < 4; ++i) { int xx = x + dir[i].first; int yy = y + dir[i].second; if (xx >= 1 && x <= n && yy >= 1 && yy <= n && g[xx][yy] == g[x][y] + 1) { f[x][y] = max(f[x][y], dp(xx, yy) + 1); } } return f[x][y]; }; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { int step = dp(i, j); if (step > d || (step == d && g[i][j] < r)) { d = step; r = g[i][j]; } } } printf("Case #%lld: %lld %lld\n", T, r, d); return; } signed main() { IOS; int T; cin >> T; for (int i = 1; i <= T; ++i) { solve(i); } return 0; }
边栏推荐
- typescript63-索引签名类型
- 工作3年,回想刚入门和现在的今昔对比,笑谈一下自己的测试生涯
- 17-VMware Horizon 2203 虚拟桌面-Win10 手动桌面池浮动(十七)
- Advanced Redis
- Shared memory + inotify mechanism to achieve multi-process low-latency data sharing
- 【instancetype类型 Objective-C】
- 微信小程序仿input组件、虚拟键盘
- Takeda Fiscal 2022 First Quarter Results Strong; On Track to Achieve Full-Year Management Guidance
- Promise (三) async/await
- 合工大苍穹战队视觉组培训Day9——相机标定
猜你喜欢
Hash 这些知识你也应该知道
一天学会从抓包到接口测试,通过智慧物业项目深度解析
Shiny04---Application of DT and progress bar in shiny
Task flow scheduling tool AirFlow,, 220804,,
更改小程序原生radio的颜色及大小
IO process thread -> communication between processes -> day7
Redis进阶
Put Cloudflare on the website (take Tencent Cloud as an example)
Week 8 Document Clustering
腾讯实习总结
随机推荐
Kioxia and Aerospike Collaborate to Improve Database Application Performance
技术分析模式(八)双顶和底
UDP broadcast
Put Cloudflare on the website (take Tencent Cloud as an example)
1、Citrix XenDesktop 2203之AD域系统安装(一)
《PyTorch深度学习实践》第十一课(卷积神经网络CNN高级版)
概率与期望部分题解
小程序input框不允许输入负数
UDP组(多)播
技术分析模式(十)头肩图案
开源中国活动合作说明书
MySQL:order by排序查询,group by分组查询
Shiny04---Application of DT and progress bar in shiny
typescript63-索引签名类型
真实字节跳动测试开发面试题,拿下年薪50万offer。
今天虚竹哥又发现了一款好用的国产化API工具
Mysql主从延迟的原因和解决方案
Database table insert data
IO process thread -> communication between processes -> day7
文本特征化方法总结