当前位置:网站首页>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; }
边栏推荐
- MySql面试题总结
- 对数据类型而言运算符无效。运算符为 add,类型为 text。
- 【instancetype类型 Objective-C】
- 给网站套上Cloudflare(以腾讯云为例)
- Hong Kong International Jewellery Show and Hong Kong International Diamond, Gem and Pearl Show kick off
- [instancetype type Objective-C]
- Week 8 Document Clustering(文本聚类)
- golang-条件语句
- PCI Pharma Services Announces Multi-Million Dollar Expansion of UK Manufacturing Facility to Meet Growing Demand for Global High Potency Drug Manufacturing Services to Support Oncology Treatment
- (4) Rotating object detection data roLabelImg to DOTA format
猜你喜欢
随机推荐
Hong Kong International Jewellery Show and Hong Kong International Diamond, Gem and Pearl Show kick off
在anaconda Promat界面import torch通过,在jupyter notebook中报错的问题(仅提供思路理解!)
武田公司2022财年第一季度业绩强劲;正稳步实现全年的管理层指引目标
Technical Analysis Mode (7) Playing the Gap
女生做软件测试会不会成为一个趋势?
typescript66-分析partial的实现
Task flow scheduling tool AirFlow,, 220804,,
任务流调度工具AirFlow,,220804,,
typescript67-索引查询类型
在STM32中使用printf函数
Flink学习10:使用idea编写WordCount,并打包运行
MySQL:基础部分
浮点数基础知识
共享内存+inotify机制实现多进程低延迟数据共享
MySQL: basic part
ndk编译so库
Modeling of the MAYA ship
开源中国活动合作说明书
C# FileSystemWatcher
Source code analysis of Nacos configuration service (full)








