๐ง๐ป [Python] ๋ฐฑ์ค 1915 ๊ฐ์ฅ ํฐ ์ ์ฌ๊ฐํ
Gold 4 - DP
์ธ๋ฑ์ค๊ฐ ๋ฒ์ด๋์ง ์๋ ์ ์์, ์, ์ผ์ชฝ, ์ธ์ชฝ ์์ ์ซ์๋ค ์ค min ๊ฐ์ ๊ตฌํ ๋ค์์ 1์ ๋ํด์ค๋ค
์ฝ๋
N, M = map(int, input().split())
matrix = [list(map(int, input())) for _ in range(N)]
dp_table = [[0] * M for _ in range(N)]
for i in range(N):
for j in range(M):
if matrix[i][j] == 1:
dp_table[i][j] = 1
if 0 <= i - 1 and 0 <= j - 1:
dp_table[i][j] = min(dp_table[i - 1][j], dp_table[i - 1][j - 1], dp_table[i][j - 1]) + 1
result = 0
for d in dp_table:
result = max(result, max(d))
print(result ** 2)
์๊ฐ ์ด๊ณผ๊ฐ ๋ฌ๋ ์ฝ๋
- ์์ ํ์์ ๊ธฐ๋ฐ์ผ๋ก ํ์ด๋ฅผ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ฌ์ค์ for๋ฌธ์ 4๋ฒ์ ํด์ผ ํ๋ค...
N, M = map(int, input().split())
def square(i, j, length):
for r in range(i, length + i):
for c in range(j, length + j):
if matrix[r][c] == 0:
return False
return True
matrix = [list(map(int, input())) for _ in range(N)]
l = N
flag = False
while flag == False:
for i in range(N):
if flag == True:
break
for j in range(M):
if i + l <= N and j + l <= M:
flag = square(i, j, l)
if flag == True:
break
else:
break
l -= 1
print((l + 1) ** 2)
'์๊ณ ๋ฆฌ์ฆ > DP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ๋ฐฑ์ค 10844 ์ฌ์ด ๊ณ๋จ ์ (0) | 2023.03.24 |
---|---|
[Python] ๋ฐฑ์ค 11726 2 x n ํ์ผ (0) | 2023.03.22 |