Leetcode983: 最低票价
作者:
VIELAMI | 来源:发表于
2020-05-06 11:03 被阅读0次int mincostTickets(vector<int>& days, vector<int>& costs) {
vector<int> dp(days[days.size()-1]+1, 0);
int days_idx = 0;
for (int i = 1; i < dp.size(); i++) {
if (i != days[days_idx]) {
dp[i] = dp[i - 1];
}
else {
int tmp = min(dp[max(0, i - 1)] + costs[0], dp[max(0, i - 7)] + costs[1]);
dp[i] = min(tmp, dp[max(0, i - 30)] + costs[2]);
days_idx++;
}
}
return dp[dp.size() - 1];
}
本文标题:Leetcode983: 最低票价
本文链接:https://www.haomeiwen.com/subject/wfmightx.html
网友评论