当前位置:网站首页>记忆化搜索 AcWing 901. 滑雪
记忆化搜索 AcWing 901. 滑雪
2022-07-03 08:41: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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Phpstudy 80 port occupied W10 system
- [concurrent programming] consistency hash
- 796 · unlock
- Unity notes 1
- Transmit pictures with Base64 encoding
- Deep parsing JVM memory model
- C language student management system based on linked list, super detailed
- Deeply understand the underlying data structure of MySQL index
- Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
- Constraintlayout's constraintset dynamically modifies constraints
猜你喜欢

Servlet的生命周期

Es8 async and await learning notes

请求参数的发送和接收

数据库原理期末复习

Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)

了解小程序的笔记 2022/7/3

Simple demo of solving BP neural network by gradient descent method

Unity Editor Extension - drag and drop

Monotonic stack -503 Next bigger Element II

Annotations simplify configuration and loading at startup
随机推荐
Chocolate installation
第一个Servlet
如何应对数仓资源不足导致的核心任务延迟
Mortgage Calculator
Analysis of Alibaba canal principle
分配异常的servlet
How does unity fixedupdate call at a fixed frame rate
Gradle's method of dynamically modifying APK package name
Annotations simplify configuration and loading at startup
Unity editor expansion - the design idea of imgui
[linear table] basic operation of bidirectional linked list specify node exchange
Alibaba canal actual combat
数据库原理期末复习
Redux - learning notes
producer consumer problem
Collection interface
Advanced OSG collision detection
Jupyter remote server configuration and server startup
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
URL backup 1