- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution983.java
More file actions
Latest commit
48 lines (44 loc) · 1.39 KB
/
Copy pathSolution983.java
File metadata and controls
48 lines (44 loc) · 1.39 KB
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
importjava.util.*;
/**
* Created by slade on 2020/1/30.
*/
publicclassSolution983 {
publicintmincostTickets(int[] days, int[] costs) {
int[] dp = newint[366];
Set<Integer> hashset = newHashSet<Integer>();
for (intday : days
) {
hashset.add(day);
}
for (inti = 1; i < 366; i++) {
if (hashset.contains(i)) {
inttmp1 = Integer.MAX_VALUE;
inttmp2 = Integer.MAX_VALUE;
inttmp3 = Integer.MAX_VALUE;
if (i - 1 >= 0) {
tmp1 = dp[i - 1] + costs[0];
} else {
tmp1 = costs[0];
}
if (i - 7 >= 0) {
tmp2 = dp[i - 7] + costs[1];
} else {
tmp2 = costs[1];
}
if (i - 30 >= 0) {
tmp3 = dp[i - 30] + costs[2];
} else {
tmp3 = costs[2];
}
dp[i] = Math.min(Math.min(tmp1, tmp2), tmp3);
} else {
dp[i] = dp[i - 1];
}
}
returndp[365];
}
publicstaticvoidmain(String[] args) {
Solution983solution983 = newSolution983();
System.out.println(solution983.mincostTickets(newint[]{1,2,3,4,5,6,7,8,9,10,30,31}, newint[]{2, 7, 15}));
}
}