当前位置:网站首页>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;
}
边栏推荐
- 2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- Troubleshooting of high CPU load but low CPU usage
- Laravel Web框架
- Liang Ning: 30 lectures on brain map notes for growth thinking
- Advanced API (use of file class)
- Use the jvisualvm tool ----- tocmat to start JMX monitoring
- Modify MySQL password
- 2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
- How does the insurance company check hypertension?
猜你喜欢

EasyExcel

dataworks自定義函數開發環境搭建

vmware虚拟机C盘扩容

Pits encountered in the use of El checkbox group

深度学习参数初始化(一)Xavier初始化 含代码

Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
![[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*](/img/1f/f579110a408c5b5a094733be57ed90.jpg)
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*

Selenium key knowledge explanation

【类和对象】深入浅出类和对象

Integration test practice (1) theoretical basis
随机推荐
机械观和系统观的科学思维方式各有什么特点和作用
Basic components and intermediate components
mongodb
每日刷題記錄 (十一)
php安装composer
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
MySQL mistakenly deleted the root account and failed to log in
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
Asynchronous programming: async/await in asp Net
Golang operation redis: write and read hash type data
Getting started with pytest
Troubleshooting of high CPU load but low CPU usage
HMS core helps baby bus show high-quality children's digital content to global developers
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
万卷书 - 价值投资者指南 [The Education of a Value Investor]
Mise en place d'un environnement de développement de fonctions personnalisées
JMeter JSON extractor extracts two parameters at the same time
Distributed ID
Laravel框架 踩坑(一)
How does the insurance company check hypertension?