DevYoon

[SWEA] 1952. 수영μž₯ λ³Έλ¬Έ

PS/SWEA

[SWEA] 1952. 수영μž₯

gimewn 2022. 4. 5. 22:26

link πŸ”— https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PpFQaAQMDFAUq 

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

 

1️⃣ DFS μ‚¬μš© → λ§€κ°œλ³€μˆ˜λ‘œ 달(month)와 μš”κΈˆν•©κ³„ μ‚¬μš©

2️⃣ 1일 μš”κΈˆμ œ μ‚¬μš©ν–ˆμ„ λ•Œ, 1달 μš”κΈˆμ œ μ‚¬μš©ν–ˆμ„ λ•Œ, 3달 μš”κΈˆμ œ μ‚¬μš©ν–ˆμ„ λ•Œ, 1λ…„ μš”κΈˆμ œ μ‚¬μš©ν–ˆμ„ λ•Œ

3️⃣ Min = 1λ…„ μš”κΈˆμ œ

 

def dfs(month, sums):
    global cost, Min
    if month > 11:
        if Min > sums:
            Min = sums
        return
    dfs(month+1, sums+(cost[0]*m[month]))
    dfs(month+1, sums+cost[1])
    dfs(month+3, sums+cost[2])
    dfs(month+12, sums+cost[3])

t = int(input())

for tc in range(1, t+1):
    cost = list(map(int, input().split()))
    m = list(map(int, input().split()))
    Min = cost[3] # 1λ…„ μš”κΈˆ
    dfs(0, 0) # 달, μš”κΈˆν•©κ³„

    print(f'#{tc} {Min}')