Algorithm 문제풀이
[BOJ] 백준 15686 - 치킨배달 (JAVA)
cjsong
2019. 5. 2. 23:14
조합한 경우 process(); 함수에서 최소값을 찾는다.
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
71
72
73
74
75
76
77
78
79
80
81
82
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main15686_치킨배달 {
private static int N;
private static int M;
private static int[][] map;
private static Pair[] set;
private static ArrayList<Pair> list;
private static ArrayList<Pair> pos;
static int minNum = Integer.MAX_VALUE;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken()); // 배열의 크기
M = Integer.parseInt(st.nextToken()); // 폐업시키지 않을 치킨집
map = new int[N][N];
list = new ArrayList<Pair>(); // 치킨집의 x,y 좌표 저장
pos = new ArrayList<Pair>(); // 도시 x, y 정보 저장 -> process() 호출 후 사용
set = new Pair[M]; // 치킨집에서 조합에 쓰일 배열
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < N; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
if (map[i][j] == 2) {
list.add(new Pair(i, j));
}
if (map[i][j] == 1) {
pos.add(new Pair(i, j));
}
}
}
comb(0, 0);
System.out.println(minNum);
}
public static void comb(int idx, int k) {
if (idx == M) {
process();
return;
} else {
comb(idx + 1, i + 1);
}
}
}
public static void process() {
int result = 0;
int min = Integer.MAX_VALUE;
for (int j = 0; j < set.length; j++) {
min = min > num ? num : min;
}
result += min;
}
minNum = minNum > result ? result : minNum;
}
static class Pair {
int x;
int y;
public Pair(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |