当前位置:网站首页>记忆化搜索 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 【Rust 笔记】09-特型与泛型
- Log4j2 vulnerability recurrence and analysis
- [public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
- Monotonic stack -42 Connect rainwater
- MySQL containerization (1) docker installation MySQL
- Sequence of map implementation classes
- UE4 source code reading_ Bone model and animation system_ Animation process
- Simple demo of solving BP neural network by gradient descent method
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
- [concurrent programming] atomic operation CAS
猜你喜欢

Try to reprint an article about CSDN reprint

MySQL 8

SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time

I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made

DOM 渲染系统(render mount patch)响应式系统

Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)

OpenGL learning notes

Introduction to hexadecimal coding

JS non Boolean operation - learning notes

Es8 async and await learning notes
随机推荐
MySQL index types B-tree and hash
Unity editor expansion - the design idea of imgui
Really explain the five data structures of redis
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
createjs easeljs
[RPC] RPC remote procedure call
Osgconv tool usage
[rust notes] 11 practical features
Deep parsing JVM memory model
[concurrent programming] collaboration between threads
[rust notes] 13 iterator (Part 1)
Dom4j traverses and updates XML
[concurrent programming] thread foundation and sharing between threads
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Deeply understand the underlying data structure of MySQL index
Redis cluster series 4
Osganimation library parsing
Apache startup failed phpstudy Apache startup failed
Find the intersection of line segments
了解小程序的笔记 2022/7/3