Minimum Cost For Tickets

Given travel days and ticket costs for 1-day, 7-day, and 30-day passes, return the minimum cost needed to cover all travel days. This is a reusable-choice DP where each ticket choice can cover multiple future days.

Input Format

days = travel days, costs = [1-day, 7-day, 30-day pass costs]

Output Format

minimum total ticket cost

Constraints

  • 1 <= days.length <= 365; 1 <= costs.length == 3; 1 <= days[i] <= 365

Examples

Example 1:

Input:

days = [1,4,6,7,8,20]
costs = [2,7,15]

Output:

11

Explanation:

The cheapest plan costs 11.

Example 2:

Input:

days = [2]
costs = [2,7,15]

Output:

2

Explanation:

A single 1-day pass is enough.

Loading...
Minimum Cost For Tickets - Dp Knapsack