forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbac2798_blackjack.java
More file actions
70 lines (50 loc) · 1.41 KB
/
bac2798_blackjack.java
File metadata and controls
70 lines (50 loc) · 1.41 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
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
class bac2798_blackjack {
static int N = 1000001;
static Scanner sc = new Scanner(System.in);
static ArrayList<Integer> AL = new ArrayList<>();
static boolean[] visited;
static int dst_value = 0;
static int answer=0;
public static void main(String[] args) {
AL.clear();
int input = sc.nextInt();
dst_value = sc.nextInt();
visited = new boolean[input];
solution(input);
System.out.println(answer);
}
public static void solution(int input)
{
//입력
for(int i =0; i<input; i++)
AL.add(sc.nextInt());
Collections.sort(AL, Collections.reverseOrder());
for(int i=0; i<AL.size(); i++) {
visited[i] = true;
dfs(i, 0, AL.get(i));
if(answer == dst_value)
break;
visited[i] = false;
}
}
public static void dfs(int start, int count, int sum)
{
if(dst_value < sum)
return;
if(count == 2) {
answer = Math.max(answer, sum);
return;
}
for(int i =0; i<AL.size(); i++)
{
if(i==start || (visited[i] == true))
continue;
if(answer == dst_value)
break;
visited[i] = true;
dfs(i,count+1, sum+AL.get(i));
visited[i] = false;
}
}
}