#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 101;
int n;
int arr[MAX][MAX];
int visited[MAX][MAX];
typedef struct {
int a, b;
}Move;
Move mv[4] = { {1,0},{-1,0},{0,1},{0,-1} };
void dfs(int i,int j,int h) {
for (int k = 0; k < 4; k++) {
int mi = i + mv[k].a;
int mj = j + mv[k].b;
if (mi >= 0 && mi < n && mj >= 0 && mj < n) {
if (arr[mi][mj] > h && visited[mi][mj] == -1) {
visited[mi][mj] = 1;
dfs(mi, mj, h);
}
}
}
}
int main(void) {
cin >> n;
int maxheight = -1;
int answer = 0;
for (int i = 0; i < n; i++) {
for (int j= 0; j < n; j++) {
cin >> arr[i][j];
maxheight = max(maxheight, arr[i][j]);
}
}
for (int i = 0; i < maxheight; i++) {
memset(visited, -1, sizeof(visited));
int counts = 0;
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (arr[j][k] > i && visited[j][k] == -1) {
visited[j][k] = 1;
dfs(j, k, i);
counts++;
}
}
}
answer = max(answer,counts);
}
cout << answer << endl;
}
'백준 알고리즘 > DFS' 카테고리의 다른 글
백준 미세먼지 안녕 C++ (0) | 2019.10.15 |
---|---|
백준 15683번 C++ (0) | 2019.09.19 |
백준 12100번 C++ (0) | 2019.09.19 |
백준 2667번 C++ (0) | 2019.02.25 |
백준 1260번 C++ (0) | 2019.02.19 |