Skip to content

Commit 54e7a2c

Browse files
authored
Merge pull request #13 from AlgorithmWithGod/khj20006
[20250203] BOJ / 골드5 / 차트 / 권혁준
2 parents fa54cf1 + d6fee17 commit 54e7a2c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
20+
static int N;
21+
static int ans = 0;
22+
static int[] A = new int[8];
23+
24+
static void sol(int pos, int choose, int[] arr) {
25+
if(pos == N) {
26+
int res = 0;
27+
for(int i=1;i<N;i++) {
28+
if(arr[i] < 50) continue;
29+
for(int j=0;j<i;j++){
30+
if(arr[j] == arr[i]-50) {
31+
res++;
32+
break;
33+
}
34+
}
35+
}
36+
ans = Math.max(ans, res);
37+
return;
38+
}
39+
for(int i=0;i<N;i++) {
40+
if((choose & (1<<i)) != 0) continue;
41+
arr[pos+1] = arr[pos] + A[i];
42+
sol(pos+1, choose | (1<<i), arr);
43+
arr[pos+1] = 0;
44+
}
45+
}
46+
47+
public static void main(String[] args) throws Exception {
48+
49+
N = Integer.parseInt(br.readLine());
50+
nextLine();
51+
for(int i=0;i<N;i++) A[i] = nextInt();
52+
sol(0, 0, new int[N+1]);
53+
54+
bw.write(ans+"\n");
55+
56+
bwEnd();
57+
}
58+
59+
}
60+
61+
```

0 commit comments

Comments
 (0)