洛谷1434
主要坑点就是每个点至少都有一个连续的坡
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
int record[105][105];
int matrix[105][105];
int n,m;
int res;
bool vis[105][105];
int ans;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int dfs(int x,int y){
if(record[x][y]) return record[x][y];
fi(i,0,3){
int p = x + dx[i];
int q = y + dy[i];
if(p > 0 && q > 0 && p <= n && q <= m){
if(!vis[p][q] && matrix[p][q] < matrix[x][y]){
vis[p][q] = true;
record[x][y] = max(record[x][y],1 + dfs(p,q));
// cout << x << " " << y << " " << record[x][y] << endl;
vis[p][q] = false;
}
}
}
if(record[x][y] == 0) return record[x][y] = 1;
else
return record[x][y];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
fi(i,1,n) fi(j,1,m) cin >> matrix[i][j];
fi(i,1,n) fi(j,1,m) vis[i][j] = true,dfs(i,j),vis[i][j] = false;
fi(i,1,n) fi(j,1,m) res = max(record[i][j],res);
cout << res << endl;
#ifdef DEBUG
//freopen(D:\in.txt,r,stdin);
#endif
return 0;
}
hack数据
3 3
3 2 4
1 2 5
2 1 4
3
3 3
3 0 3
0 3 0
3 0 3
2