当前位置:网站首页>Memory search acwing 901 skiing
Memory search acwing 901 skiing
2022-07-03 08:51:00 【T_ Y_ F666】
Memory search AcWing 901. skiing
Original link
Algorithm tags
Dynamic programming Memory search
Ideas

Code
#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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- [concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
- I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
- [RPC] RPC remote procedure call
- 22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
- 20220630学习打卡
- Facial expression recognition based on pytorch convolution -- graduation project
- 单调栈-84. 柱状图中最大的矩形
- Query XML documents with XPath
- 第一个Servlet
- Binary tree sorting (C language, int type)
猜你喜欢

树形DP AcWing 285. 没有上司的舞会
![[RPC] RPC remote procedure call](/img/dc/872204ea47fcff04cdb72e18a2a4ef.jpg)
[RPC] RPC remote procedure call
![[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle](/img/b7/7bf2a4a9ab51364352aa5e0a196b6d.jpg)
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
![[redis] redis persistent RDB vs AOF (source code)](/img/57/b6a86c49cedee31fc00dc5d1372023.jpg)
[redis] redis persistent RDB vs AOF (source code)
![[concurrent programming] working mechanism and type of thread pool](/img/51/d21428a7c95c0a5177e8198742e78c.jpg)
[concurrent programming] working mechanism and type of thread pool

JS ternary operator - learning notes (with cases)

Monotonic stack -42 Connect rainwater

Phpstudy 80 port occupied W10 system

How to use Jupiter notebook

Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
随机推荐
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
Solution of 300ms delay of mobile phone
【Rust 笔记】08-枚举与模式
How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
Animation_ IK overview
Redux - learning notes
On the setting of global variable position in C language
Eating fruit
[redis] redis persistent RDB vs AOF (source code)
Baidu editor ueeditor changes style
Final review of Database Principles
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
Unity editor expansion - controls, layouts
LinkedList set
[concurrent programming] explicit lock and AQS
ES6 promise learning notes
Monotonic stack -503 Next bigger Element II
Concurrent programming (VI) ABA problems and solutions under CAS
cres