Part6.2_완전탐색_깊이,넓이 우선탐색활용_휴가(DFS)

Eugenius1st·2022년 2월 2일
0

Python_algorithm

목록 보기
45/83

선생님 코드

import sys
sys.stdin = open("input.txt", "rt")

def DFS(L,sum):
    global res
    if L == n+1 :
        if sum>res:
            res = sum

    else:
        if L+T[L] <= n+1: #현재 날짜에 걸리는 기간을 더한 것이다.
            print(L, L+T[L], sum+P[L])
            DFS(L+T[L], sum+P[L])
        print(L, sum)
        DFS(L+1,sum) #그냥 1씩 증가하는 것
            

if __name__ == "__main__":
    n = int(input())
    T = list() # 걸리는 시간
    P = list() # 금액

    for i in range(n):
        a, b = map(int,input().split())
        T.append(a)
        P.append(b)
    res=-2147000000
    T.insert(0,0)
    P.insert(0,0)
    DFS(1,0)
    print("lastRES:",res)
    

다시 해봐라.. L에 초점을 둔 것이 중요..!

profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글