-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSolution.java
38 lines (29 loc) Β· 1.24 KB
/
Solution.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
package DP.swea1952;
import java.io.*;
import java.util.StringTokenizer;
public class Solution {
static int T;
static int[] fare, plan, dp;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DP/swea1952/sample_input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
fare = new int[4];
plan = new int[13];
dp = new int[13];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < 4; i++) fare[i] = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= 12; i++) plan[i] = Integer.parseInt(st.nextToken());
for (int i = 1; i <= 12; i++) {
dp[i] = dp[i-1] + Math.min(fare[0] * plan[i], fare[1]);
if (i >= 3) dp[i] = Math.min(dp[i], dp[i-3] + fare[2]);
}
sb.append("#").append(t).append(" ").append(Math.min(dp[12], fare[3])).append("\n");
}
System.out.println(sb.toString());
}
}