Skip to content

Commit c343476

Browse files
committed
1114
1 parent ded149d commit c343476

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/bronze/BOJ2309/src/Main.java

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,41 @@
11
import java.util.*;
22

33
public class Main {
4-
static boolean flag = false;
4+
static boolean flag ;
55

6-
public static void DFS(List<Integer> man, int depth, List<Integer> visited) {
7-
if (flag) {
8-
return;
6+
public static void main(String[] args) {
7+
Scanner sc =new Scanner(System.in);
8+
int [] man = new int [9];
9+
boolean [] check = new boolean[9];
10+
for (int i = 0; i < 9; i++) {
11+
man[i]=sc.nextInt();
912
}
10-
if (depth == 7) {
11-
int total = 0;
12-
for (int i = 0; i < visited.size(); i++) {
13-
total += visited.get(i);
14-
}
15-
if (total == 100) {
13+
Arrays.sort(man);
14+
FindMan(man, check, 0,0);
1615

17-
for (int i = 0; i < visited.size(); i++) {
18-
System.out.println(visited.get(i));
19-
}
20-
flag = true;
21-
}
22-
} else {
23-
for (int i = depth; i < man.size(); i++) {
24-
if (!visited.contains(man.get(i))) {
25-
visited.add(man.get(i));
26-
DFS(man, depth + 1, visited);
27-
visited.remove(visited.size() - 1);
28-
29-
}
30-
}
31-
}
3216

3317

3418
}
35-
36-
public static void main(String[] args) {
37-
List<Integer> numbers = new ArrayList<>();
38-
Scanner sc = new Scanner(System.in);
39-
for (int i = 0; i < 9; i++) {
40-
int N = sc.nextInt();
41-
numbers.add(N);
19+
private static void FindMan(int [] man, boolean [] check, int cac, int r){
20+
if(flag==true){
21+
return;
4222
}
43-
List<Integer> visited = new ArrayList<>();
44-
45-
46-
Collections.sort(numbers);
47-
DFS(numbers, 0, visited);
23+
if(r==7 && cac==100){
24+
for (int i = 0; i < check.length; i++) {
25+
if(check[i]==true){
26+
System.out.println(man[i]);
27+
}
28+
}
29+
flag=true;
4830

31+
}
32+
for (int i = r; i < 9; i++) {
33+
if(!check[i]){
34+
check[i]=true;
35+
FindMan(man,check,cac+man[i], r+1);
36+
check[i]=false;
37+
}
4938

39+
}
5040
}
5141
}

0 commit comments

Comments
 (0)