Skip to content

Commit 28b8d5b

Browse files
committed
[level 2] Title: 땅따먹기, Time: 209.25 ms, Memory: 31.5 MB -BaekjoonHub
1 parent 7976f49 commit 28b8d5b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# [level 2] 땅따먹기 - 12913
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12913?language=python3)
4+
5+
### 성능 요약
6+
7+
메모리: 31.5 MB, 시간: 209.25 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 연습문제
12+
13+
### 채점결과
14+
15+
정확성: 59.8<br/>효율성: 40.2<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 12월 31일 15:56:19
20+
21+
### 문제 설명
22+
23+
<p>땅따먹기 게임을 하려고 합니다. 땅따먹기 게임의 땅(land)은 총 N행 4열로 이루어져 있고, 모든 칸에는 점수가 쓰여 있습니다. 1행부터 땅을 밟으며 한 행씩 내려올 때, 각 행의 4칸 중 한 칸만 밟으면서 내려와야 합니다. <strong>단, 땅따먹기 게임에는 한 행씩 내려올 때, 같은 열을 연속해서 밟을 수 없는 특수 규칙이 있습니다.</strong> </p>
24+
25+
<p>예를 들면, </p>
26+
27+
<p>| 1 | 2 | 3 | 5 |</p>
28+
29+
<p>| 5 | 6 | 7 | 8 |</p>
30+
31+
<p>| 4 | 3 | 2 | 1 |</p>
32+
33+
<p>로 땅이 주어졌다면, 1행에서 네번째 칸 (5)를 밟았으면, 2행의 네번째 칸 (8)은 밟을 수 없습니다. </p>
34+
35+
<p>마지막 행까지 모두 내려왔을 때, 얻을 수 있는 점수의 최대값을 return하는 solution 함수를 완성해 주세요. 위 예의 경우, 1행의 네번째 칸 (5), 2행의 세번째 칸 (7), 3행의 첫번째 칸 (4) 땅을 밟아 16점이 최고점이 되므로 16을 return 하면 됩니다.</p>
36+
37+
<h5>제한사항</h5>
38+
39+
<ul>
40+
<li>행의 개수 N : 100,000 이하의 자연수</li>
41+
<li>열의 개수는 4개이고, 땅(land)은 2차원 배열로 주어집니다.</li>
42+
<li>점수 : 100 이하의 자연수</li>
43+
</ul>
44+
45+
<h5>입출력 예</h5>
46+
<table class="table">
47+
<thead><tr>
48+
<th>land</th>
49+
<th>answer</th>
50+
</tr>
51+
</thead>
52+
<tbody><tr>
53+
<td>[[1,2,3,5],[5,6,7,8],[4,3,2,1]]</td>
54+
<td>16</td>
55+
</tr>
56+
</tbody>
57+
</table>
58+
<h5>입출력 예 설명</h5>
59+
60+
<p>입출력 예 #1<br>
61+
문제의 예시와 같습니다.</p>
62+
63+
64+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def solution(land):
2+
for i in range(1, len(land)):
3+
for j in range(len(land[0])):
4+
land[i][j] += max(land[i-1][:j] + land[i-1][j+1:])
5+
return max(land[-1])

0 commit comments

Comments
 (0)