All Survived?
Time limit8sMemory limit1024 MB
Given each player's team and hit probability, choose targets to maximize the chance that no ally is popped before the game ends.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Probability, Game theory
- Solved
- No attempts yet
Problem
You are playing a first-person shooter with your friends. In this game, players are divided into two teams that fight each other. Each player wears a balloon on top of the head, and players try to pop the balloons of the players on the opposing team.
Players are numbered from 1 through . These numbers are called the action orders. Each player also has a real number called the hit probability. The game consists of phases. In the -th phase (), the player with action order (the attacker) takes the following action.
- If the attacker's balloon has already been popped, the attacker is dead and the phase is skipped without any action.
- If all opposing team members are dead, the phase is skipped as well.
- Otherwise, the attacker chooses one living opposing player as the target. The choice may depend on the results of previous actions. The attack succeeds with the attacker's hit probability, regardless of the target. If the attack succeeds, the target's balloon is popped and the target is killed.
The game ends when all phases are completed.
You do not want any player on your team to be killed. Choose targets optimally and calculate the probability that all players on your team stay alive until the game ends. Assume that the opposing players choose their targets at random.
Input
The input consists of multiple datasets. The number of datasets does not exceed 50. Each dataset has the following format.
is the number of players, an integer from 2 to 300. For each , is either "Ally" or "Enemy", meaning the player with action order is on your team or the opposing team. is the hit probability, a real number from 0 to 1 with 9 digits after the decimal point. Both teams have at least one player.
The input ends with a line containing 0.
Output
For each dataset, print one line containing the probability that all players on your team stay alive when targets are chosen optimally. The absolute or relative error must be at most .