当前位置:网站首页>691. Cube IV
691. Cube IV
2022-07-27 08:38:00 【Pursue people far away】
Vincenzo Decided to make a cube IV, But all the budget is only enough to make a square maze .
It is a perfect maze , Each room is square , And 4 door ( Four sides, one side 1 individual ).
There is a number in every room .
A person's number in the next room is only larger than the number in the current room 1 Under the circumstances , To move from the current room to the next room .
Now? ,Vincenzo All rooms are assigned a unique number (1,2,3,…S2) And then S2 I put myself in the maze , Every room 1 individual , among S Is the side length of the maze .
The person who can move the most times will win .
Figure out who will win , And the number of rooms he will be able to reach .
Input format
The first line contains integers T, Expressing common ownership T Group test data .
The first row of each set of test data contains integers S, Represents the side length of the maze .
Next S That's ok , Each row contains S It's an integer , Represents the room number distribution of the specific maze , Attention should be paid to 1,2,3,…S2 this S2 A digital , Each number appears only once .
Output format
Each group of data outputs a result , Each result takes up one line .
The result is expressed as Case #x: r d, among x It's the group number ( from 1 Start ),r Is the room number of the winner's original room ,d Is the number of rooms he can reach .
If more than one person can reach the same number of rooms , Then the person with the smallest room number in the original room will win .
Data range
1≤T≤100,
1≤S≤1000
sample input :
2
2
3 4
1 2
3
1 2 9
5 3 8
4 6 7
sample output :
Case #1: 1 2
Case #2: 6 4
Code :
// Memory search
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, g[N][N], f[N][N];
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
int dfs(int x, int y)
{
int &v = f[x][y];
if (v != -1)
return v;
v = 1;
for (int i = 0; i < 4; i++)
{
int a = x + dx[i], b = y + dy[i];
if (a >= 0 && a < n && b >= 0 && b < n && g[a][b] == g[x][y] + 1)
v = max(v, dfs(a, b) + 1);
}
return v;
}
int main()
{
int T;
cin >> T;
for (int k = 1; k <= T; k++)
{
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cin >> g[i][j];
}
memset(f, -1, sizeof f);
int id, cnt = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
int t = dfs(i, j);
if (t > cnt || t == cnt && id > g[i][j])
{
cnt = t;
id = g[i][j];
}
}
}
printf("Case #%d: %d %d\n", k, id, cnt);
}
return 0;
}
边栏推荐
- QPushButton 按钮的创建与简单应用
- 我用字符画出了一个谷爱凌!
- Attack and defense world MFW
- JS advanced knowledge - function
- while Loop
- Alibaba cloud international receipt message introduction and configuration process
- ROS2安装时出现Connection failed [IP: 91.189.91.39 80]
- Weekly learning summary
- Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
- 众昂矿业:新能源行业快速发展,氟化工产品势头强劲
猜你喜欢

Eval and assert execute one sentence Trojan horse
![[geek challenge 2019] finalsql 1](/img/a7/857d47639fcb38e0055a2444206b8c.png)
[geek challenge 2019] finalsql 1

“寻源到结算“与“采购到付款“两者有什么不同或相似之处?

Forced login, seven cattle cloud upload pictures

General Administration of Customs: the import of such products is suspended

MCDF top level verification scheme

Explain cache consistency and memory barrier

Realization of background channel group management function

情人节,我用字符画出了一个对象!

Day4 --- flask blueprint and rest ful
随机推荐
Chapter 2 foreground data display
CMD command and NPM command
Solution to the program design of the sequence structure of one book (Chapter 1)
Function realization of order system
Luogu Taotao picks apples
Cookie addition, deletion, modification and exception
众昂矿业:新能源行业快速发展,氟化工产品势头强劲
Installation and use of beef XSS
The shelf life you filled in has been less than 10 days until now, and it is not allowed to publish. If the actual shelf life is more than 10 days, please truthfully fill in the production date and pu
XxE & XML vulnerability
Flink1.15 source code reading Flink clients client execution process (reading is boring)
List delete collection elements
pytorch_ demo1
Realize SKU management in the background
百人参与,openGauss开源社区这群人都在讨论什么?
Flask project configuration
如何卸载--奇安信安全终端管理系统
UVM入门实验1
[ciscn2019 southeast China division]web11 1
Eval and assert execute one sentence Trojan horse