아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Exact Change

시간 제한1초메모리 제한1024 MB

요약
각 패키지 값 집합에서 부분집합의 합으로 만들 수 없는 가장 작은 양의 정수를 구한다.
난이도

보통10점 중 5점

유형
정렬, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Whenever the UCF Programming Team travels to World Finals, Glenn likes having the exact amount of money necessary for any purchase, so that he doesn’t have to count and receive change. Of course, most countries don’t have many different denominations of coins, so Glenn creates different “packages” with him, each with some particular amount of money, in cents. Glenn would like to know which amount of money (in cents), is the smallest that he can’t pay for exactly, with some combination of his packages.

Given a list of positive integers, determine the smallest integer that can’t be represented as the sum of some subset of the integers on the list.

입력

The first input line contains a single positive integer, n (1 < n ≤ 100), indicating the number of sets of coin packages to evaluate. Each of the n input sets follows. The first line of each input set contains only an integer, c (1 ≤ c < 31), representing the number of different packages of coin for that input set. The following line contains exactly c positive integers, each separated by a single space, representing the value of each of the c packages in cents. The sum of these c integers is guaranteed not to exceed 109. Note that the package values are not necessarily distinct, i.e., there may be multiple packages with the same value.

출력

For each set of packages, first output “Set #i: ” where i is the input data set number, starting with 1. Follow this with a single positive integer, the smallest value that can’t be represented as a sum of the values of a subset of the packages given. Note that a package value can be used at most once in a subset unless there are multiple packages with that value (if there are m occurrences of a package value, up to m occurrences of that value can be used in a subset). Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.

예제1

  1. 예제 1

    입력
    3
    6
    12 8 1 2 4 100
    3
    1 2 3
    6
    3 1 3 2 3 3
    
    예상 출력
    Set #1: 28
    
    Set #2: 7
    
    Set #3: 16