当前位置:网站首页>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; }
边栏推荐
- Flink学习10:使用idea编写WordCount,并打包运行
- After the firewall iptable rule is enabled, the system network becomes slow
- 自媒体人一般会从哪里找素材呢?
- 400 times performance improvement 丨 swap valuation optimization case calculation
- 专用机终端安装软件后报IP冲突
- typescript65-映射类型(keyof)
- Technical Analysis Mode (7) Playing the Gap
- 【instancetype类型 Objective-C】
- 《PyTorch深度学习实践》第十课(卷积神经网络CNN)
- 17-VMware Horizon 2203 virtual desktop-Win10 manual desktop pool floating (seventeen)
猜你喜欢
字节面试流程及面试题无私奉献,吐血整理
Falsely bamboo brother today and found a localization of API to use tools
【LeetCode】235.二叉搜索树的最近公共祖先
Day9 of Hegong Daqiong team vision team training - camera calibration
re正则表达式
任务流调度工具AirFlow,,220804,,
UDP group (multi)cast
RNote108---Display the running progress of the R program
typescript66-分析partial的实现
今天虚竹哥又发现了一款好用的国产化API工具
随机推荐
【JVM调优】Xms和Xmx为什么要保持一致
2022熔化焊接与热切割操作证考试题及模拟考试
typescript61-泛型工具类型(pick)
游戏思考19:游戏多维计算相关:点乘、叉乘、点线面距离计算
Rapid Medical's Ultra-Small and Only Adjustable Thromb Retriever Receives FDA Clearance
RK3568 environment installation
任务流调度工具AirFlow,,220804,,
技术分析模式(七)发挥差距
更改小程序原生radio的颜色及大小
RNote108---显示R程序的运行进度
Promise (三) async/await
基于快速行进平方法的水面无人船路径规划
UDP broadcast
真实字节跳动测试开发面试题,拿下年薪50万offer。
不太会讲爱,其实已经偷偷幸福很久啦----我们的故事
Source code analysis of Nacos configuration service (full)
AI+视频技术助力保障校园安全,校园智能安防平台该如何建设?
原来使Maya Arnold也能渲染出高质量作品!超赞小技巧
Falsely bamboo brother today and found a localization of API to use tools
17-VMware Horizon 2203 virtual desktop-Win10 manual desktop pool floating (seventeen)