I: City Destruction
https://open.kattis.com/problems/city
Let denote the (minimum) number of moves required to destroy all the cities from through , assuming that the city (if exists) was not destroyed before the city.
Let denote the (minimum) number of moves required to destroy all the cities from through , assuming that the city (if exists) was destroyed before the city.
Initial condition:
,
For , it is easy to see that the transitions are
If we assume city was destroyed earlier, then our health reduces by and the number of extra moves required is .
Otherwise, the number of extra moves required is .
In this case, since city has exploded already, our health has already reduced to .
If we assume city was destroyed earlier, then our health reduces by and the number of extra moves required is .
Otherwise, the number of extra moves required is .
The final answer is .
Remember to use long integers to avoid overflow!
Last updated