Skip to content

Commit ae72a2a

Browse files
authored
Merge pull request #103 from YoonYn9915/main
YoonYn9915/ 12์›” 2์ฃผ์ฐจ/ 2๋ฌธ์ œ
2 parents 449b815 + fb082c8 commit ae72a2a

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
N = int(input())
2+
3+
# ๊ฐ€๋กœ, ์„ธ๋กœ, ๋Œ€๊ฐ์„  ์ˆœ
4+
dx = [0, 1, 1]
5+
dy = [1, 0, 1]
6+
7+
8+
def dfs(x, y, dir):
9+
# ์ด๋ฏธ ๋ฐฉ๋ฌธํ•œ ์ƒํƒœ๋ผ๋ฉด ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜
10+
if memo[x][y][dir] != -1:
11+
return memo[x][y][dir]
12+
13+
# ์ข…๋ฃŒ ์กฐ๊ฑด: ๋ชฉํ‘œ์— ๋„๋‹ฌํ•˜๋ฉด ๊ฒฝ๋กœ 1๊ฐœ ์ถ”๊ฐ€
14+
if x == N - 1 and y == N - 1:
15+
return 1
16+
17+
# ๊ฒฝ๋กœ ์ˆ˜
18+
paths = 0
19+
20+
for dir_idx in range(3):
21+
# ํ˜„์žฌ ๋ฐฉํ–ฅ์—์„œ ์ด๋™ ๋ถˆ๊ฐ€๋Šฅํ•œ ๋ฐฉํ–ฅ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
22+
if (dir == 0 and dir_idx == 1) or (dir == 1 and dir_idx == 0):
23+
continue
24+
25+
newX = x + dx[dir_idx]
26+
newY = y + dy[dir_idx]
27+
28+
# ์ด๋™ ๊ฐ€๋Šฅํ•œ์ง€ ๊ฒ€์‚ฌ
29+
if 0 <= newX < N and 0 <= newY < N and arr[newX][newY] == 0:
30+
if dir_idx == 2: # ๋Œ€๊ฐ์„ 
31+
if arr[newX - 1][newY] == 1 or arr[newX][newY - 1] == 1:
32+
continue
33+
34+
# DFS ํƒ์ƒ‰
35+
paths += dfs(newX, newY, dir_idx)
36+
37+
# ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”๋ชจ์ด์ œ์ด์…˜์— ์ €์žฅ
38+
memo[x][y][dir] = paths
39+
return paths
40+
41+
42+
# ์ž…๋ ฅ
43+
arr = [list(map(int, input().split())) for _ in range(N)]
44+
45+
# ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ์ดˆ๊ธฐํ™”: -1๋กœ ์ฑ„์›€
46+
memo = [[[-1] * 3 for _ in range(N)] for _ in range(N)]
47+
48+
# DFS ์‹œ์ž‘
49+
print(dfs(0, 1, 0))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'''
2+
1. ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ์ง„ํ–‰
3+
1.1 ๋ฌธ์ œ ์š”๊ฑด์— ๋”ฐ๋ผ ์ตœ์•…์˜ ๊ฒฝ์šฐ๋Š”
4+
500 * 500 * 5(ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ์ข…๋ฅ˜) * 4(90๋„ ํšŒ์ „ ๊ฒฝ์šฐ์˜ ์ˆ˜) * 4(๋Œ€์นญํ•œ ํ›„ 90๋„ ํšŒ์ „ ๊ฒฝ์šฐ์˜ ์ˆ˜).
5+
N(1์–ต)์ด 1์ดˆ๋ผ๊ณ  ๊ฐ€์ •ํ•œ๋‹ค๋ฉด 2์ดˆ๋ฉด ์ถฉ๋ถ„ํ•˜๋‹ค๊ณ  ํŒ๋‹จ.
6+
2. ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ์˜ ์ข…๋ฅ˜๋ณ„๋กœ, ํšŒ์ „๊ณผ ๋Œ€์นญ์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ชจ๋‘ ๊ณ ๋ คํ•˜์—ฌ ๋ชจ์–‘ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค.
7+
3. ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์—์„œ ๋ชจ๋“  ์นธ์„ ์ˆœํšŒํ•˜๋ฉฐ ๋ชจ๋“  ๋ชจ์–‘ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฒ€์‚ฌํ•˜์—ฌ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ๋Š”๋‹ค.
8+
9+
'''
10+
11+
N, M = map(int, input().split())
12+
13+
arr = [list(map(int, input().split())) for _ in range(N)]
14+
15+
# ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ๋ชจ์–‘, ์‹œ์ž‘์ ์„ ๊ธฐ์ค€์œผ๋กœ ๋”ํ•ด์•ผ ํ•  dx, dy์ž„.
16+
shape = [[(0, 1), (0, 2), (0, 3)], [(1, 0), (2, 0), (3, 0)],
17+
[(0, 1), (1, 0), (1, 1)],
18+
[(1, 0), (1, 1), (2, 1)], [(0, -1), (1, -1), (1, -2)],
19+
[(1, 0), (1, -1), (2, -1)], [(0, 1), (1, 1), (1, 2)],
20+
[(1, 0), (2, 0), (2, 1)], [(0, 1), (0, 2), (1, 0)],
21+
[(0, 1), (1, 1), (2, 1)], [(0, 1), (0, 2), (-1, 2)],
22+
[(1, 0), (2, 0), (2, -1)], [(0, 1), (0, 2), (1, 2)],
23+
[(1, 0), (2, 0), (0, 1)], [(1, 0), (1, 1), (1, 2)],
24+
[(1, 0), (1, 1), (1, -1)], [(1, 0), (1, 1), (2, 0)],
25+
[(0, -1), (1, 0), (0, 1)], [(0, 1), (-1, 1), (1, 1)]
26+
]
27+
28+
29+
def calc(i, j, tet):
30+
sum = arr[i][j]
31+
for dx, dy in tet:
32+
newX = i + dx
33+
newY = j + dy
34+
#์ข…์ด์˜ ๋ฒ”์œ„๋ฅผ ๋„˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ข…์ด ์นธ์˜ ์ˆ˜ ๋”ํ•˜๊ธฐ
35+
if 0 <= newX < N and 0 <= newY < M:
36+
sum += arr[newX][newY]
37+
else:
38+
return 0
39+
return sum
40+
41+
42+
ans = 0
43+
for i in range(N):
44+
for j in range(M):
45+
for tet in shape:
46+
temp = calc(i, j, tet) # ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋ชจ์–‘์˜ ํ•ฉ ๊ณ„์‚ฐ
47+
ans = max(temp, ans)
48+
49+
print(ans)

0 commit comments

Comments
ย (0)