[D4] 가능한 시험 점수 - 3752
성능 요약
메모리: 108,640 KB, 시간: 755 ms, 코드길이: 968 Bytes
제출 일자
2023-11-16 10:07
출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
class Solution {
static HashSet<Integer> result;
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int tc = 1; tc <= T; tc++) {
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0; i < n; i++){
nums[i] = sc.nextInt();
}
result = new HashSet<>();
result.add(0);
for(int i = 0; i < n; i++){
addScore(nums[i]);
}
System.out.println("#" + tc + " " + result.size());
}
}
private static void addScore(int score) {
HashSet<Integer> set = new HashSet<>();
Iterator<Integer> iterator = result.iterator();
while(iterator.hasNext()){
set.add(iterator.next() + score);
}
result.addAll(set);
}
}
'알고리즘 - SWEA > D4' 카테고리의 다른 글
[SW expert Academy] SWEA 1249번 보급로 자바(Java) (0) | 2023.11.18 |
---|---|
[SW expert Academy] SWEA 1226번 미로1 자바(Java) (1) | 2023.11.18 |
[SW expert Academy] SWEA 1232번 사칙연산 자바(Java) (0) | 2023.11.16 |
[SW expert Academy] SWEA 1224번 계산기3 자바(Java) (0) | 2023.11.15 |
[SW expert Academy] SWEA 1223번 계산기2 자바(Java) (0) | 2023.11.15 |