-
Notifications
You must be signed in to change notification settings - Fork 0
/
양팔저울.java
47 lines (35 loc) · 891 Bytes
/
양팔저울.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.IOException;
public class Main {
static int k,sum,ans;
static int []v = new int[14];
static boolean []a = new boolean[3000000];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
k = Integer.parseInt(br.readLine());
int sum =0;
StringTokenizer st =new StringTokenizer(br.readLine());
for(int i =0; i<k; i++)
{
v[i] = Integer.parseInt(st.nextToken());
sum+=v[i];
}
dfs(0,0);
System.out.println(sum-ans);
}
public static void dfs(int n, int cur)
{
if(cur >=1)
{
if(!a[cur])
ans++;
a[cur]=true;
}
if(n ==k) return;
dfs(n+1, cur+v[n]);
dfs(n+1, cur-v[n]);
dfs(n+1,cur);
}
}