Seven Up

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

요약
일곱 장의 시작 카드가 주어질 때, 무작위로 섞은 나머지 카드로 Seven Up 게임이 끝날 때까지 걸리는 턴 수의 기댓값을 구한다.
난이도

어려움10점 중 8점

유형
확률, 동적 계획법, 시뮬레이션, 수학
정답자
아직 제출이 없습니다

문제

The one-player game of Seven Up is played with a standard deck of 52 cards - each card has one of thirteen possible faces which we denote by A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, and K. There are exactly four cards of each face.

Initially, seven cards are dealt face down in positions numbered 1 through 7. The ace (A) has value 11, the cards with faces 2--7 have corresponding values 22 through 77, and the remaining cards do not have any value.

A single turn consists of the player drawing a card from the top of the deck (initially having 52−7=4552-7 = 45 cards). The following steps are repeated until the turn is ended:

  • if the card has no value (i.e. the face is not one of A, 2, 3, 4, 5, 6, or 7), the turn has ended,
  • otherwise if the card in the position corresponding to the value of the card held by the player is already face up, the turn has ended,
  • otherwise the player swaps the card they are holding with the card in the corresponding position except the card they placed in this position is now face up, the current turn continues

At the end of a turn, if all seven positions have a face-up card, the game ends.

If the remaining 4545 cards are randomly permuted so each ordering is equally likely, what is the expected number of turns until the game completes?

More specifically, if for any 1≤k≤451 \leq k \leq 45 we let p_kp\_k denote the probability (over the random ordering of the remaining 4545 cards) the game finishes after kk turns are completed. You should compute ∑_k=145k⋅p_k\sum\_{k = 1}^{45} k \cdot p\_k.

입력

Input consists of a single string consisting of exactly 7 characters from A23456789TJQK denoting the faces of the 7 cards that were dealt face down into their corresponding positions. No face will appear more than four times in this string.

출력

Output a single value giving the expected number of turns until the game completes. Your answer should have an absolute or relative error of less than 10−610^{-6}.

예제2

  1. 예제 1

    입력
    A9Q22T5
    
    예상 출력
    19.88129713423831
    
  2. 예제 2

    입력
    JQQQKKK
    
    예상 출력
    20.91314505643106