T-coding
백준 1029 그림 교환 / Python 본문
728x90
728x90
https://www.acmicpc.net/problem/1029
코드
더보기
n = int(input())
arr = []
for i in range(n):
arr.append([int(j) for j in input()])
dp = [[[0] * 10 for _ in range(n)] for _ in range(1 << n)]
def dfs(now, artist, cost):
if dp[now][artist][cost] != 0:
return dp[now][artist][cost]
cnt = 0
for i in range(1, n):
if arr[artist][i] >= cost and now & (1 << i) <= 0:
cnt = max(cnt, 1 + dfs(now | (1 << i), i, arr[artist][i]))
dp[now][artist][cost] = cnt
return cnt
print(dfs(1, 0, 0) + 1)
728x90
300x250
'Baekjoon' 카테고리의 다른 글
백준 1913 달팽이 / Python (0) | 2023.03.18 |
---|---|
백준 1074 Z / Python (0) | 2023.03.18 |
백준 1022 소용돌이 예쁘게 출력하기 / Python (0) | 2023.03.18 |
백준 7569 토마토 / Python (0) | 2023.03.17 |
백준 25206 너의 평점은 / Python (0) | 2023.03.16 |