강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

박진호님의 프로필 이미지
박진호

작성한 질문수

파이썬 알고리즘 문제풀이 입문(코딩테스트 대비)

2. 휴가(DFS)

반례를 못찾겠습니다 ㅠㅠ

작성

·

152

0

mport sys

input = sys.stdin.readline

def sol():

  global maxN

  n = int(input())

  table = []

  maxN = -1e9

  for i in range(n):

    a,b = map(int,input().split())

    table.append((i+1,a,b))

  def dfs(s, tot):

    global maxN

    if tot > maxN:

      maxN = tot

    for i in range(s, n):

      if s == 0:

        dfs(i+1, tot+table[i][2])

      elif table[s-1][0] + table[s-1][1] <= table[i][0]:

        dfs(i+1, tot+table[i][2])

  dfs(0, 0)

  print(maxN)

sol()

4번 케이스에서 오류가 나는데 반례를 찾지 못하겠습니다 ㅠㅠ

강의 항상 잘 보고있습니다!

답변 1

0

김태원님의 프로필 이미지
김태원
지식공유자

안녕하세요^^

5

3 10 

2 15

1 10

1 30

2 10

이 입력의 답이 45인데 위 코드는 55가 나옵니다. 분석해보세요.

박진호님의 프로필 이미지
박진호

작성한 질문수

질문하기