-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswea_3752.java
More file actions
58 lines (43 loc) · 1.56 KB
/
swea_3752.java
File metadata and controls
58 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
import java.io.*;
class swea_3752
{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
List<Integer> answer = new ArrayList<>();
for(int i=0;i<N;i++) {
int M = Integer.parseInt(br.readLine());
int sum = 0;
int[] arr = new int[M];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j=0;j<M;j++) {
arr[j] = Integer.parseInt(st.nextToken());
sum += arr[j];
}
boolean[] dp = new boolean[sum+1];
dp[0] = true;
for(int j=0;j<M;j++) {
List<Integer> addList = new ArrayList<>();
for(int k=0;k<dp.length;k++) {
if(dp[k]) {
addList.add(k + arr[j]);
}
}
for(Integer index : addList) {
dp[index] = true;
}
}
int cnt = 0;
for(int j=0;j<dp.length;j++) {
if(dp[j]){
cnt++;
}
}
answer.add(cnt);
}
for(int i=0;i<N;i++) {
System.out.printf("#%d %d\n", i+1, answer.get(i));
}
}
}