-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[BOJ] 14500 테트로미노(브루트포스, 복습).cpp
More file actions
69 lines (62 loc) · 1.75 KB
/
[BOJ] 14500 테트로미노(브루트포스, 복습).cpp
File metadata and controls
69 lines (62 loc) · 1.75 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
int map[500][500];
bool check[500][500];
int n, m;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int ans = 0;
void go(int x, int y, int sum, int cnt) {
if (cnt == 4) {
if (ans < sum) ans = sum;
return;
}
if (x < 0 || x >= n || y < 0 || y >= m) return;
if (check[x][y]) return;
check[x][y] = true;
for (int k = 0; k < 4; k++) {
go(x+dx[k], y+dy[k], sum+map[x][y], cnt+1);
}
check[x][y] = false;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> map[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
go(i, j, 0, 0);
if (j+2 < m) {
int temp = map[i][j] + map[i][j+1] + map[i][j+2];
// ㅗ 모양 체크
if (i-1 >= 0) {
int temp2 = temp + map[i-1][j+1];
if (ans < temp2) ans = temp2;
}
// ㅜ 모양 체크
if (i+1 < n) {
int temp2 = temp + map[i+1][j+1];
if (ans < temp2) ans = temp2;
}
}
if (i+2 < n) {
int temp = map[i][j] + map[i+1][j] + map[i+2][j];
// ㅏ 모양 체크
if (j+1 < n) {
int temp2 = temp + map[i+1][j+1];
if (ans < temp2) ans = temp2;
}
// ㅓ 모양 체크
if (j-1 >= 0) {
int temp2 = temp + map[i+1][j-1];
if (ans < temp2) ans = temp2;
}
}
}
}
cout << ans << endl;
return 0;
}