-
Notifications
You must be signed in to change notification settings - Fork 0
/
10710.java
74 lines (52 loc) · 1.82 KB
/
10710.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
70
71
72
73
74
import java.io.*;
import java.util.*;
public class Main {
static class Node {
int index;
int value;
public Node(int index, int value) {
this.index = index;
this.value = value;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[] dist = new int[N];
int[] cost = new int[M];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
dist[i] = Integer.parseInt(st.nextToken());
}
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
cost[i] = Integer.parseInt(st.nextToken());
}
int[][] dp = new int[N][M]; // N 번째 장소를 M에 지나옴!
for (int i = 0; i < N; i++) {
Arrays.fill(dp[i], Integer.MAX_VALUE);
}
for (int i = 0; i < M; i++) {
dp[0][i] = dist[0] * cost[i];
}
for (int i = 1; i < N; i++) {
for (int j = 1; j < M; j++) {
for(int k=0; k<j; k++){
if (dp[i - 1][k] == Integer.MAX_VALUE) {
continue;
}
dp[i][j] = Math.min(dp[i-1][k] + cost[j] * dist[i], dp[i][j]);
}
}
}
int min = Integer.MAX_VALUE;
for (int i = N - 1; i < M; i++) {
min = Math.min(min, dp[N - 1][i]);
}
bw.write(min + "\n");
bw.flush();
}
}