Minimizing cost of bus travel
There's a rather simple algorithm for this. 

You start at the end of the array, day 10. If you only wanted to travel from that day onwards, you could buy a 1 day, 7 day, or 30 day ticket. 1 day is optimal at a cost of 2. 

Then you check the second to last entry, day 9. If you only wanted to travel from that day onwards, you could buy a 1 day ticket (and add the optimal combination of tickets from day 10 at cost 2, total cost = 4), or a 7 or 30 day ticket, which is more expensive. 

Again from day 8, the cheapest is a day ticket plus the optimal combination from day 9 on, total cost 6. But then you check day 5: If you buy a single day ticket, you pay 2 plus 6 for travel from day 8, total 7. But if you buy a weekly ticket, the cost is only 7. You then proceed to the beginning of the array. 

int n = 6;
int dates [n+1] = { 1, 3, 5, 8, 9, 10, infinity };
int ticket [n];
int cost [n+1];

cost [n] = 0;

for i = n-1 downto 0
    cost for 1 day = 2 + cost [i+1]
    let k7 = smallest k where dates [k] ≥ dates [i] + 7
    cost for 7 day = 7 + cost [k7]
    let k30 = smallest k where dates [k] ≥ dates [i] + 30
    cost for 30 days = 25 + cost [k30]

    if cost for 1 day is smallest
        ticket [i] = 1
        cost [i] = cost for 1 day
    else if cost for 7 day is smallest
        ticket [i] = 7
        cost [i] = cost for 7 days
    else
        ticket [i] = 30
        cost [i] = cost for 30 days
    endif


That's easily done in O (n) for any fixed number of different tickets. The answer would be a bit different if you have "weekly" tickets that are valid from Monday to Sunday, or from Sunday to Saturday, depending on the country, and "monthly" tickets that are valid from the 1st to the last day of a month.