P1434 [SHOI2002]滑雪 题解
题目传送门
我记得我刚学OI时教练wangk就讲过,鸽到现在才写与其是弱智题解,不如说是纪念
还挺简单的,就是个记忆法搜索模板题
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
#include<chrono>
#include<random>
#include<unordered_map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rll register long long
#define ri register int
//#define int long long
const int N=110;
const int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int r,c,ans;
int m[N][N],l[N][N];
inline ll read(){
ll x=0,y=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')
y=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*y;
}
inline int dfs(int x,int y){
if(l[x][y])
return l[x][y];
l[x][y]=1;
for(ri i=0;i<=3;i++){
int vx=x+dx[i],vy=y+dy[i];
if(vx>0&&vy>0&&vx<=r&&vy<=c&&m[x][y]>m[vx][vy]){
dfs(vx,vy);
l[x][y]=max(l[x][y],l[vx][vy]+1);
}
}
return l[x][y];
}
signed main(){
r=read(),c=read();
for(ri i=1;i<=r;i++)
for(ri j=1;j<=c;j++)
m[i][j]=read();
for(ri i=1;i<=r;i++)
for(ri j=1;j<=c;j++)
ans=max(ans,dfs(i,j));
printf("%d",ans);
return 0;
}
```