Skip to content

Commit 9e426d3

Browse files
authored
[20250203] BOJ / 골드5 / 차트 / 이강현
1 parent ceeb5aa commit 9e426d3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

lkhyun/202502/03 BOJ 차트.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.io.BufferedReader;
2+
import java.io.BufferedWriter;
3+
import java.io.InputStreamReader;
4+
import java.io.OutputStreamWriter;
5+
import java.util.*;
6+
public class Main {
7+
static BufferedReader br;
8+
static BufferedWriter bw;
9+
static int N;
10+
static int[] comb;
11+
static boolean[] visited;
12+
static int[] dogs;
13+
static int max = 0;
14+
public static void main(String[] args) throws Exception {
15+
br = new BufferedReader(new InputStreamReader(System.in));
16+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
17+
N = Integer.parseInt(br.readLine());
18+
StringTokenizer st = new StringTokenizer(br.readLine());
19+
20+
dogs = new int[N];
21+
comb = new int[N];
22+
visited = new boolean[N];
23+
for(int i=0;i<N;i++){
24+
dogs[i] = Integer.parseInt(st.nextToken());
25+
}
26+
combination(0);
27+
bw.write(max + "");
28+
bw.flush();
29+
}
30+
31+
public static void combination(int depth){
32+
if(depth == N){
33+
int count = 0;
34+
for(int j=0;j<N-1;j++){
35+
int sum = comb[j];
36+
for(int k=j+1;k<N;k++){
37+
if(sum == 50){count++; break;}
38+
else if(sum > 50){break;}
39+
sum += comb[k];
40+
}
41+
}
42+
if(max<count){max = count;}
43+
return;
44+
}
45+
46+
for(int i=0;i<N;i++){
47+
if(visited[i]){continue;}
48+
visited[i] = true;
49+
comb[depth] = dogs[i];
50+
combination(depth+1);
51+
visited[i] = false;
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)