Skip to content

Commit 450c803

Browse files
committed
[PGS]#12905. 가장 큰 정사각형 찾기/lv2/3h(힌트)
https://school.programmers.co.kr/learn/courses/30/lessons/12905
1 parent a5813c0 commit 450c803

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
유형 : DP
3+
IDEA : dp(i,j)의 값에 만들 수 있는 정사각형 최대 길이로 할당하기
4+
FLOW
5+
- if board[i][j] == 1 이면
6+
-> dp[i,j] = min( (i-1,j), (i,j-1) , (i-1,j-1)) + 1 대입
7+
"""
8+
def solution(board):
9+
answer = 0
10+
dp = [[0]*len(board[0]) for _ in range(len(board))]
11+
#1. 반복문으로 board[i,j] 찾기
12+
for i in range(len(board)):
13+
for j in range(len(board[0])):
14+
if board[i][j] == 1 :
15+
#2. dp로 (i,j)을 정사각형 오른쪽 아래 칸으로 가지는 최대 변의 길이 구하기
16+
if 0<=i-1<=len(board) and 0<=j-1 < len(board[0]):
17+
dp[i][j] = min(dp[i-1][j] , dp[i][j-1] , dp[i-1][j-1]) +1
18+
# print(dp[i][j])
19+
20+
else :
21+
dp[i][j] = 1
22+
answer= max(answer , dp[i][j])
23+
24+
# print(dp)
25+
# print(answer)
26+
return answer**2

0 commit comments

Comments
 (0)