LA 2730

LA 2730 - Toll

 * http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=2730

Summary
You have to travel from one place to another via a network of cities and villages. You are supposed to bring P items into the destination place. Each time you enter a village, you have to pay 1 item for entering it, each time you enter a city you have to pay 1 item per each 20 items you brought in (rounded up). Find the smallest amount of items you should have at the beginning of your journey.

Explanation
This is just a concealed Dijkstra's algorithm. For each location compute the smallest number of items sufficient to get from there to the destination. Note that the algorithm has to be run "backwards", from the location where you end your journey.

Implementations
The input graph is small, there is no need to implement any fancy optimizations, brute force will do.

Input
1 a Z 19 a Z 5 A D D X A b b c c X 39 A X -1

Output
Case 1: 20 Case 2: 44