当前位置:网站首页>记忆化搜索 AcWing 901. 滑雪
记忆化搜索 AcWing 901. 滑雪
2022-07-27 10:35:00 【T_Y_F666】
记忆化搜索 AcWing 901. 滑雪
原题链接
算法标签
动态规划 记忆化搜索
思路

代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 305;
int a[N][N],f[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n, m;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int dp(int x, int y){
if(f[x][y]!=-1){
return f[x][y];
}
f[x][y]=1;
rep(i, 0, 4){
int xx=x+dx[i], yy=y+dy[i];
if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[xx][yy]<a[x][y]){
f[x][y]=max(f[x][y], dp(xx, yy)+1);
}
}
return f[x][y];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read(), m=read();
rep(i, 1, n+1){
rep(j, 1, m+1){
a[i][j]=read();
}
}
memset(f, -1, sizeof f);
int ans=0;
rep(i, 1, n+1){
rep(j, 1, m+1){
ans=max(ans, dp(i, j));
}
}
printf("%lld", ans);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Taishan Office Technology Lecture: scaling and opening files
- How to create a.Net image with diagnostic tools
- 栈 AcWing 3302. 表达式求值
- 迭代次数和熵之间关系的一个验证试验
- Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
- properties文件
- 区间问题 AcWing 906. 区间分组
- Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
- Neural network learning notes
- Ten year structure five year life-07 young and vigorous transformation
猜你喜欢

如何组装一个注册中心

推导STO双中心动能积分的详细展开式

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

ethereum rpc

Longest ascending subsequence model acwing 1012. Sister Cities

Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin

推导重叠积分的详细展开式 STO overlap integrals

Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen

计算重叠积分的第二种方法

迭代次数的差异与信息熵
随机推荐
What changes will metauniverse bring to the music industry in the trillion market?
推导STO双中心动能积分的详细展开式
Maximized array sum after 13 K negations
中国剩余定理 AcWing 204. 表达整数的奇怪方式
SQL Server2000数据库错误
荒野觅踪---寻找迭代次数
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
最长上升子序列模型 AcWing 1010. 拦截导弹
Play with the cluster configuration center and learn about the Taier console
黑白像素分布对迭代次数的影响
349两个数组的交集和01两数之和
Redis+caffeine two-level cache enables smooth access speed
Background color style modification on table hover in antd
BeautifulSoup的使用
FAQs of "relay chain" and "dot" in Poka ecosystem
A measurement method of 5g air interface one-way delay and its reliability
区间问题 AcWing 906. 区间分组
Longest ascending subsequence model acwing 1012. Sister Cities
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
最长上升子序列模型 AcWing 482. 合唱队形