当前位置:网站首页>记忆化搜索 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 解决 ImportError: cannot import name 'abs' 导入tensorflow报错
- Use of beautifulsoup
- 49 letter ectopic grouping and 242 effective letter ectopic words
- Antd table+checkbox default value display
- TensorFlow张量运算函数集
- Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
- 10 complete half of the questions
- 博弈论 AcWing 892. 台阶-Nim游戏
- [QNX hypervisor 2.2 user manual]9.9 logger
- Description and feelings
猜你喜欢

博弈论 AcWing 892. 台阶-Nim游戏

Knapsack model acwing 423. Picking herbs

JVM judges that the object is dead, and practices verify GC recycling

最长上升子序列模型 AcWing 482. 合唱队形

Kangaroo cloud stack based on CBO in spark SQL optimization

FAQs of "relay chain" and "dot" in Poka ecosystem

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft

ethereum rpc

发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析

15 design movie rental system
随机推荐
7 row K with the weakest combat effectiveness in the matrix
IO stream_ Character stream, IO stream summary, IO stream case summary
Application of 5g private network in smart medicine
2022牛客多校 (3)J.Journey
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
Use of beautifulsoup
Neural network learning notes
ACM warm-up Exercise 2 in 2022 summer vacation (summary)
最长上升子序列模型 AcWing 482. 合唱队形
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
Compete for the key battle of stock users and help enterprises build a perfect labeling system - 01 live review
49 letter ectopic grouping and 242 effective letter ectopic words
发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
Taishan Office Technology Lecture: scaling and opening files
Maximized array sum after 13 K negations
Use of parsel
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
如何创建一个带诊断工具的.NET镜像