Leetcode983: 最低票价

2020-05-06  本文已影响0人  VIELAMI
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];
}
上一篇 下一篇

猜你喜欢

热点阅读