-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gold III] Title: 욕심쟁이 판다, Time: 904 ms, Memory: 51352 KB -BaekjoonHub
- Loading branch information
1 parent
3251051
commit 08e7ca1
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# [Gold III] 욕심쟁이 판다 - 1937 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/1937) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 51352 KB, 시간: 904 ms | ||
|
||
### 분류 | ||
|
||
깊이 우선 탐색, 다이나믹 프로그래밍, 그래프 이론, 그래프 탐색 | ||
|
||
### 제출 일자 | ||
|
||
2024년 7월 10일 12:06:55 | ||
|
||
### 문제 설명 | ||
|
||
<p>n × n의 크기의 대나무 숲이 있다. 욕심쟁이 판다는 어떤 지역에서 대나무를 먹기 시작한다. 그리고 그 곳의 대나무를 다 먹어 치우면 상, 하, 좌, 우 중 한 곳으로 이동을 한다. 그리고 또 그곳에서 대나무를 먹는다. 그런데 단 조건이 있다. 이 판다는 매우 욕심이 많아서 대나무를 먹고 자리를 옮기면 그 옮긴 지역에 그 전 지역보다 대나무가 많이 있어야 한다.</p> | ||
|
||
<p>이 판다의 사육사는 이런 판다를 대나무 숲에 풀어 놓아야 하는데, 어떤 지점에 처음에 풀어 놓아야 하고, 어떤 곳으로 이동을 시켜야 판다가 최대한 많은 칸을 방문할 수 있는지 고민에 빠져 있다. 우리의 임무는 이 사육사를 도와주는 것이다. n × n 크기의 대나무 숲이 주어져 있을 때, 이 판다가 최대한 많은 칸을 이동하려면 어떤 경로를 통하여 움직여야 하는지 구하여라.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 대나무 숲의 크기 n(1 ≤ n ≤ 500)이 주어진다. 그리고 둘째 줄부터 n+1번째 줄까지 대나무 숲의 정보가 주어진다. 대나무 숲의 정보는 공백을 사이로 두고 각 지역의 대나무의 양이 정수 값으로 주어진다. 대나무의 양은 1,000,000보다 작거나 같은 자연수이다.</p> | ||
|
||
### 출력 | ||
|
||
<p>첫째 줄에는 판다가 이동할 수 있는 칸의 수의 최댓값을 출력한다.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
sys.setrecursionlimit(10**6) | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
g = [list(map(int, input().split())) for _ in range(n)] | ||
|
||
dx = [-1, 0, 1, 0] | ||
dy = [0, 1, 0, -1] | ||
|
||
|
||
def isInner(x, y): | ||
return 0 <= x < n and 0 <= y < n | ||
|
||
|
||
dp = [[0] * n for _ in range(n)] | ||
|
||
|
||
# dp[x][y]는 (x,y)에서 시작했을 때 최댓값 | ||
def DFS(x, y): | ||
if dp[x][y]: | ||
return dp[x][y] | ||
|
||
dp[x][y] = 1 # 만약 한번도 시작안했다면 해당 값으로 시작 | ||
for i in range(4): | ||
nx = x + dx[i] | ||
ny = y + dy[i] | ||
if not isInner(nx,ny): continue | ||
|
||
if g[nx][ny] > g[x][y]: # 이동 가능 | ||
dp[x][y] = max(dp[x][y], DFS(nx,ny) + 1) | ||
|
||
return dp[x][y] | ||
|
||
res = 0 | ||
for i in range(n): | ||
for j in range(n): | ||
res = max(res, DFS(i,j)) | ||
|
||
print(res) |