当前位置:网站首页>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;
}
边栏推荐
- The education of a value investor
- 【类和对象】深入浅出类和对象
- Win 10 find the port and close the port
- Summary of remote connection of MySQL
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- 2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
- On the practice of performance optimization and stability guarantee
- Advanced API (local simulation download file)
- dataworks自定義函數開發環境搭建
- Golang operation redis: write and read kV data
猜你喜欢
Sorting out the core ideas of the pyramid principle
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
JUC forkjoinpool branch merge framework - work theft
每日刷題記錄 (十一)
dataworks自定義函數開發環境搭建
dataworks自定义函数开发环境搭建
Specified interval inversion in the linked list
My 2020 summary "don't love the past, indulge in moving forward"
golang操作redis:写入、读取kv数据
Operation principle of lua on C: Foundation
随机推荐
Integration test practice (1) theoretical basis
The essence of interview
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
DBNet:具有可微分二值化的实时场景文本检测
On the practice of performance optimization and stability guarantee
vmware虚拟机C盘扩容
(翻译)异步编程:Async/Await在ASP.NET中的介绍
Advanced API (byte stream & buffer stream)
10000小时定律不会让你成为编程大师,但至少是个好的起点
Operation principle of lua on C: Foundation
[classes and objects] explain classes and objects in simple terms
Golang operation redis: write and read kV data
Reading notes of "learn to ask questions"
dataworks自定義函數開發環境搭建
JMeter test result output
Interface learning
The education of a value investor
Class and object summary
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
深度学习参数初始化(一)Xavier初始化 含代码