提交时间:2024-03-30 16:35:48

运行 ID: 140624

#include<iostream> #include<algorithm> using namespace std; const int N = 110, way[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int r, c, a[N][N], f[N][N], ans = 1; struct Group{ int t, x, y; bool operator < (const Group & o) const{ return t > o.t; } } st[N*N]; int main(){ cin >> r >> c; for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ f[i][j] = 1; cin >> a[i][j]; st[i*r+j].x = i, st[i*r+j].y = j; st[i*r+j].t = a[i][j]; } } sort(st, st + (r * c)); for(int i = 0; i < r*c; i++){ for(int j = 0; j < 4; j++){ int ax = st[i].x + way[j][0], ay = st[i].y + way[j][1]; if(ax < 0 || ay < 0 || ax >= r || ay >= c) continue; if(a[st[i].x][st[i].y] >= a[ax][ay]) continue; f[st[i].x][st[i].y] = max(f[st[i].x][st[i].y], f[ax][ay] + 1); } ans = max(ans, f[st[i].x][st[i].y]); } cout << ans; return 0; }