ALGORITHM/SWEXPERT|SOFTEER
[Softeer] 택배 마스터 광우 (lv.3)
0298
2021. 11. 2. 22:45
https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=581
Softeer
제한시간 : C/C++/Java/Python/JS(2초) | 메모리 제한 : 256MB 여름 휴가를 떠나기 위해 용돈이 필요했던 광우는 H택배 상하차 아르바이트를 지원 했다. 광우는 평소에 운동을 하지않아 힘쓰는 데에 자신
softeer.ai
2021
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
|
import java.util.*;
import java.io.*;
public class Main {
public static int N, M, K, answer;
public static int[] arr;
public static boolean[] vtd;
public static void solve(int[] parcel) {
int idx = 0;
int total = 0;
for(int i = 0; i < K; i++) {
int sum = 0;
for(int j = idx; ;j++) {
if(sum + parcel[j%N] > M) {
idx = j;
break;
}
else sum += parcel[j%N];
}
total += sum;
}
answer = Math.min(answer, total);
}
public static void comb(int cnt, int[] p) {
if(cnt == N) {
solve(p);
return;
}
for(int i = 0; i < N; i++) {
if(!vtd[i]) {
vtd[i] = true;
p[cnt] = arr[i];
comb(cnt+1, p);
vtd[i] = false;
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
answer = 987654321;
arr = new int[N];
vtd = new boolean[N];
st = new StringTokenizer(bf.readLine());
for(int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int[] p = new int[N];
comb(0, p);
System.out.println(answer);
}
}
|
cs |