-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main1535_안녕_bruteforce.java
69 lines (59 loc) · 1.49 KB
/
Main1535_안녕_bruteforce.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
//BOJ :: 1535 안녕
//2019-03-25
public class Main1535_안녕_bruteforce {
private static int N;
private static int[] power;
private static int[] happy;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine()); // 사람 수
power = new int[N]; //체력
happy = new int[N]; //기쁨
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i=0;i<N;i++) {//체력
power[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine(), " ");
for(int i=0;i<N;i++) {//기쁨
happy[i] = Integer.parseInt(st.nextToken());
}
ans = Integer.MIN_VALUE;
for(int i=1;i<=N;i++) {
set = new int[i];
select(0,i,0);
}
if (ans == Integer.MIN_VALUE) {
ans = 0;
}
System.out.println(ans);
}
static int[] set;
static int ans;
public static void select(int len,int size,int k) {
if(len==size) {
int happySum = 0;
int powerSum = 100;
for(int i=0;i<set.length;i++) {
powerSum-=power[set[i]];
if(powerSum <= 0) break;
happySum+=happy[set[i]];
}
if(powerSum>0) {
if(ans < happySum) {
ans = happySum;
//System.out.println(Arrays.toString(set));
}
}
return;
}
for(int i=k;i<N;i++) {
set[len]= i;
select(len+1,size,i+1);
}
}
}