Dungeons Game
Time limit4sMemory limit2048 MB
Given n dungeons with opponents of strength s[i] and q starting states (dungeon x, strength z), find the hero's final strength when the hero reaches dungeon n.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Tree, Divide and conquer
- Solved
- No attempts yet
Problem
Robert is designing a new computer game. The game has one hero, opponents, and dungeons. The opponents are numbered from to , and the dungeons are numbered from to . Opponent () is in dungeon and has strength . Dungeon has no opponent.
The hero starts by entering dungeon with strength . Each time the hero enters dungeon (), the hero fights opponent , and one of the following happens:
- If the hero's strength is at least , the hero wins. The hero's strength increases by (). The hero then enters dungeon next ().
- Otherwise, the hero loses. The hero's strength increases by (). The hero then enters dungeon next.
may be less than, equal to, or greater than . may also be less than, equal to, or greater than . The opponent stays in dungeon with strength regardless of the result.
The game ends when the hero enters dungeon . The game ends after a finite number of fights no matter which dungeon and strength the hero starts with.
Robert wants to test the game with simulations. Each simulation gives a starting dungeon and a starting strength . For each simulation, find the hero's strength when the game ends.
Constraints
- (for all )
- (for all )
- (for all )