标签:搜索 last define mod div tps ret mes col
题目链接:https://www.luogu.com.cn/problem/P1434
想法:
记忆化搜索板子题:
#include <algorithm> #include <string> #include <string.h> #include <vector> #include <map> #include <stack> #include <set> #include <queue> #include <math.h> #include <cstdio> #include <iomanip> #include <time.h> #include <bitset> #include <cmath> #include <sstream> #include <iostream> #include <cstring> #define LL long long #define ls nod<<1 #define rs (nod<<1)+1 #define pii pair<int,int> #define mp make_pair #define pb push_back const double eps = 1e-10; const int maxn = 100 + 10; const LL mod = 1e9 + 7; const LL INF = 1e18; int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;} using namespace std; int mapp[maxn][maxn]; int f[maxn][maxn]; int n,m; int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}}; inline int dfs(int x,int y,int last) { if (f[x][y]) return f[x][y]; f[x][y] = 1; for (int i = 0;i < 4;i++) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if (mapp[xx][yy] < last && xx >= 1 && xx <= n && yy >= 1 && yy <= n) { dfs(xx,yy,mapp[xx][yy]); f[x][y] = max(f[x][y],f[xx][yy]+1); } } return f[x][y]; } int main() { cin >> n >> m; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) cin >> mapp[i][j]; } int ans = 0; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { ans = max(ans,dfs(i,j,mapp[i][j])); } } cout << ans << endl; return 0; }
标签:搜索 last define mod div tps ret mes col
原文地址:https://www.cnblogs.com/-Ackerman/p/12431484.html