Solve UVa 532 - Dungeon Master.