当前位置:网站首页>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;
}
边栏推荐
- 【code】偶尔取值、判空、查表、验证等
- Getting started with pytest
- [Code] occasionally take values, judge blanks, look up tables, verify, etc
- 【code】if (list != null && list.size() > 0)优化,集合判空实现方式
- MySQL mistakenly deleted the root account and failed to log in
- Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
- Class and object summary
- Daily question brushing record (11)
- RestHighLevelClient获取某个索引的mapping
- Unit test notes
猜你喜欢

3311. 最长算术

机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)

On the practice of performance optimization and stability guarantee
![[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

每日刷题记录 (十一)

2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)

Interfaces and related concepts

JMeter JSON extractor extracts two parameters at the same time

POI excel percentage

Pytest -- write and manage test cases
随机推荐
Distributed lock
Error c2017: illegal escape sequence
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Inno Setup 制作安装包
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
dataworks自定義函數開發環境搭建
[set theory] partition (partition | partition example | partition and equivalence relationship)
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
卡特兰数(Catalan)的应用场景
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
Reading notes of "learn to ask questions"
mysql误删root账户导致无法登录
HMS core helps baby bus show high-quality children's digital content to global developers
Unit test framework + Test Suite
Use of framework
10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
Mise en place d'un environnement de développement de fonctions personnalisées
[Code] occasionally take values, judge blanks, look up tables, verify, etc
php artisan