반응형
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
DFS 문제.
한 번이라도 수영장을 가는 날에 한해서
- 1일권 끊는 경우
- 1개월권 끊는 경우
- 3개월권 끊는 경우
로 DFS 탐색하면 된다.
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
def dfs(idx, price): | |
global answer | |
if idx >= len(days): | |
answer = min(answer, price) | |
return | |
# 1일 이용권 결제 | |
if days[idx] == 0: | |
dfs(idx+1, price) | |
else: | |
dfs(idx+1, price + (days[idx] * prices[0])) | |
# 1개월 이용권 결제 | |
dfs(idx+1, price + prices[1]) | |
# 3개월 이용권 결제 | |
dfs(idx+3, price + prices[2]) | |
T = int(input()) | |
# 여러개의 테스트 케이스가 주어지므로, 각각을 처리합니다. | |
for test_case in range(1, T + 1): | |
prices = list(map(int,input().split())) | |
days = list(map(int,input().split())) | |
# 초기값 = 1년 이용권 사용 | |
answer = prices[-1] | |
dfs(0, 0) | |
print("#{} {}".format(test_case, answer)) | |
반응형
'프로그래밍 > 코딩테스트 문제풀이' 카테고리의 다른 글
[Python] 백준 3197. 백조의 호수 (0) | 2020.07.21 |
---|---|
[Python] 백준 16918. 봄버맨 (0) | 2020.07.20 |
[Python] 백준 12015. 가장 긴 증가하는 부분수열 2(LIS) (0) | 2020.07.14 |
[Python] 백준 2644. 촌수계산 (0) | 2020.07.13 |
[Python] 백준 5014. 스타트링크 (0) | 2020.07.09 |