All Survived?

시간 제한8초메모리 제한1024 MB

요약
정해진 순서대로 n명이 행동하며, 아군의 공격 대상은 우리가 정하고 적군은 무작위로 공격할 때 아군이 한 명도 죽지 않을 확률의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 확률, 그리디, 수학
정답자
아직 제출이 없습니다

문제

You are playing a first-person shooter with your friends. In this game, n players are divided into two teams fighting against each other. Each player is crowned with a balloon on top of the head, and players try to pop the balloons of the players of the opposing team.

Players are numbered from 1 through n, which are called the action orders. Also, each player is given a real number called the hit probability. The game consists of n phases. In the i-th (i = 1, …, n) phase, the player of the action order i (the attacker) takes the following action.

  • If the balloon of the attacker has already been popped, the attacker is dead and this phase is skipped without any actions.
  • If all of the opposing team members are dead, the phase is skipped as well.
  • Otherwise, one of the opposing players alive is chosen as the target to attack. The choice may be based on the results of previous actions. The attack succeeds with the hit probability of the attacker, regardless of the target. When the attack succeeds, the balloon of the target is popped, and the target is killed.

The game ends when all of the phases are completed.

You don't want any of the players of your team to be killed. Calculate the probability of keeping all the players of your team alive until the end of the game by optimally choosing the targets. Assume that the opposing players choose their targets at random.

입력

The input consists of multiple datasets, each in the following format. The number of datasets does not exceed 50.

n

s1 p1

⋮

s**n p**n

The integer n is the number of the players between 2 and 300, inclusive. For each i = 1, …, n, s**i and p**i represent the team and the hit probability of the player of action order i, respectively. s**i is a string either of "Ally" or "Enemy", which means that the player belongs to your team or the opposite, respectively. p**i is a real number between 0 and 1, inclusive, with 9 digits after the decimal point. It is guaranteed that both teams have at least one player.

The end of the input is indicated by a line consisting of a zero.

출력

For each dataset, output in a line the probability of keeping all the players of your team alive when targets are optimally selected. The absolute or relative error must be less than or equal to 10−9.

예제1

  1. 예제 1

    입력
    3
    Ally 0.800000000
    Enemy 0.300000000
    Enemy 0.600000000
    2
    Enemy 0.444444444
    Ally 0.111111111
    5
    Ally 0.500000000
    Ally 0.750000000
    Enemy 0.400000000
    Enemy 0.100000000
    Enemy 0.800000000
    6
    Ally 0.250000000
    Ally 0.300000000
    Enemy 0.200000000
    Ally 0.800000000
    Enemy 1.000000000
    Enemy 0.750000000
    10
    Enemy 0.032876598
    Ally 0.273941411
    Ally 0.560821701
    Ally 0.798896750
    Enemy 0.559524781
    Enemy 0.627232231
    Enemy 0.864686751
    Ally 0.991458997
    Enemy 0.699768375
    Enemy 0.675523871
    0
    
    예상 출력
    0.616000000000
    0.555555556000
    0.621000000000
    0.419750000000
    0.142319776535