We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 09ff79f + eccfd54 commit 86f929aCopy full SHA for 86f929a
leetcode/cpp/dynamic programming/983.cpp
@@ -0,0 +1,25 @@
1
+// Minimum Cost for Tickets
2
+
3
+class Solution {
4
+public:
5
+ int mincostTickets(vector<int>& days, vector<int>& costs) {
6
+ int n_days = (int)days.size();
7
+ int last_day = days[n_days - 1];
8
+ vector<int> cost(last_day + 1,0);
9
+ int j = 0;
10
+ int z = 0;
11
+ for(int i = 1; i <= last_day; i++){
12
+ if(days[j] == i){
13
+ j++;
14
+ int a = INT_MAX, b = INT_MAX, c = INT_MAX;
15
+ a = cost[i - 1] + costs[0];
16
+ b = cost[max(z, i - 7)] + costs[1];
17
+ c = cost[max(z, i - 30)] + costs[2];
18
+ cost[i] = min({a, b, c});
19
+ }
20
+ else cost[i] = cost[i-1];
21
22
23
+ return cost[last_day];
24
25
+};
0 commit comments