-
Notifications
You must be signed in to change notification settings - Fork 0
/
1937.cpp
47 lines (40 loc) · 969 Bytes
/
1937.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <queue>
#define MAX(a,b) (a>b? (a):(b));
using namespace std;
int N;
int a[501][501];
int dp[501][501];
int dx[4] = { 0, 0, -1, 1 };
int dy[4] = { 1, -1, 0, 0 };
priority_queue< pair< int, pair<int, int> > > pq;
int main(){
int ans = 0;
scanf("%d", &N);
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++){
scanf("%d", &a[i][j]);
pq.push(make_pair(a[i][j], make_pair(i, j)));
}
while(!pq.empty()){
int height = pq.top().second.first;
int width = pq.top().second.second;
int cost = pq.top().first;
pq.pop();
int maxValue = 0;
dp[height][width] = 1;
for (int j = 0; j < 4; j++){
int nx = width + dx[j];
int ny = height + dy[j];
if (a[height][width] < a[ny][nx])
maxValue = MAX(maxValue, dp[ny][nx] + 1);
}
if (maxValue!=0)
dp[height][width] = maxValue;
if (ans < dp[height][width])
ans = dp[height][width];
}
printf("%d\n", ans);
return 0;
}