Editorial for DMOPC '17 Contest 1 P4 - Quests


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: r3mark

For subtask 1, brute-force all possible choices of NPCs. After checking the gold and time obtained from reaching the NPC, the problem becomes unbounded knapsack.

Time complexity: O(2NNH)

For subtask 2, the problem is exactly unbounded knapsack.

Time complexity: O(NH)

For the final subtask, consider the NPCs one by one. For each NPC, you have the choice to go to it or not. Say dp[K][0] is the answer given K hours and not going to the NPC and dp[K][1] is the answer given K hours and going to the NPC. Then dp[K][1] is the maximum of dp[Khi][0]+gi and dp[Kti][1]+qi. So the answer can be computed using this.

Time complexity: O(NH)


Comments

There are no comments at the moment.