当前位置:网站首页>691. Cube IV
691. Cube IV
2022-07-03 07:03:00 【Ray. C.L】

Ideas : Memory search ,f[i][j] Said to i,j Is the maximum number of steps from the starting point , Then the transfer equation can be obtained f[i][j] = max(f[i][j+1],f[i+1][j],f[i-1][j],f[i][j-1])+1.
Code :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int f[N][N], g[N][N];
int n;
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
int dp(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 = dx[i] + x, b = dy[i] + y;
if(a >=0 && a < n && b >=0 && b < n && g[a][b] == g[x][y] + 1){
v = max(v, dp(a,b) + 1);
}
}
return v;
}
int main()
{
int T;
scanf("%d", &T);
for(int cases = 1; cases <= T; cases++){
scanf("%d", &n);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
scanf("%d", &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 = dp(i,j);
if(t > cnt || t >= cnt && id > g[i][j]){
cnt = t;
id = g[i][j];
}
}
printf("Case #%d: %d %d\n", cases, id, cnt);
}
return 0;
}
边栏推荐
- Selenium key knowledge explanation
- Abstract learning
- Centos切换安装mysql5.7和mysql8.0
- [Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
- EasyExcel
- Pytest -- write and manage test cases
- How to plan well?
- Troubleshooting of high CPU load but low CPU usage
- crontab定时任务
- Software testing assignment - the next day
猜你喜欢

Software testing assignment - day 1

Operation principle of lua on C: Foundation

Summary of the design and implementation of the weapon system similar to the paladin of vitality
![[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet](/img/9d/42dfef67246740f0dba0c6d8f1b625.jpg)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet

Arctic code vault contributor

Reading notes of "learn to ask questions"

每日刷题记录 (十一)

卡特兰数(Catalan)的应用场景

Setting up the development environment of dataworks custom function

Win 10 find the port and close the port
随机推荐
Abstract learning
卡特兰数(Catalan)的应用场景
File links cannot be opened or downloaded in Google browser
Class and object summary
Unit test notes
Book recommendation~
Resthighlevelclient gets the mapping of an index
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
MySQL mistakenly deleted the root account and failed to log in
Golang operation redis: write and read hash type data
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
Operation principle of lua on C: Foundation
Journal quotidien des questions (11)
Application scenarios of Catalan number
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
Shim and Polyfill in [concept collection]
DBNet:具有可微分二值化的实时场景文本检测
php安装composer
Flask Foundation
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?