当前位置:网站首页>记忆化搜索 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Monotonic stack -503 Next bigger Element II
- Unity editor expansion - scrolling list
- [concurrent programming] collaboration between threads
- Collection interface
- Message queue for interprocess communication
- First Servlet
- 单调栈-84. 柱状图中最大的矩形
- [rust notes] 11 practical features
- 单调栈-42. 接雨水
- Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
猜你喜欢
Dealing with duplicate data in Excel with xlwings
Unity editor expansion - controls, layouts
分配异常的servlet
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
VIM learning notes from introduction to silk skating
Alibaba canal actual combat
第一个Servlet
Binary to decimal, decimal to binary
单调栈-42. 接雨水
请求参数的发送和接收
随机推荐
[rust notes] 11 practical features
Explain sizeof, strlen, pointer, array and other combination questions in detail
PHP function date (), y-m-d h:i:s in English case
Gradle's method of dynamically modifying APK package name
Unity editor expansion - draw lines
MySQL 8
Unity editor expansion - controls, layouts
Monotonic stack -84 The largest rectangle in the histogram
[concurrent programming] atomic operation CAS
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
注解简化配置与启动时加载
【Rust 笔记】09-特型与泛型
Drawing maze EasyX library with recursive backtracking method
【Rust笔记】05-错误处理
createjs easeljs
Solution of 300ms delay of mobile phone
第一个Servlet
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
[concurrent programming] working mechanism and type of thread pool
How does unity fixedupdate call at a fixed frame rate