반응형

@notepad_jj2

츄르사려고 코딩하는 코집사입니다.


1. [SW expert Academy] SWEA 5215번 햄버거 다이어트 파이썬(Python)

 

2. 코드

- 이 문제는 powerset 알고리즘을 이용하면 된다.

def search(index, total_score, total_cal):
    global taste

    if total_cal > L:
        return

    if index >= N:
        if total_score > taste:
            taste = total_score

        return

    search(index + 1, total_score + score_list[index], total_cal + cal_list[index])
    search(index + 1, total_score, total_cal)


T = int(input())

for i in range(1, T+1):
    N, L = map(int, input().split())
    score_list = []
    cal_list = []

    for _ in range(N):
        score, cal = map(int, input().split())
        score_list.append(score)
        cal_list.append(cal)

    taste = 0

    search(0,0,0)

    print('#'+str(i)+' '+str(taste))
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기