PivotOJ

Seven Up

시간 제한: 13000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2023-2024BOJ 30554

문제

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 527=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 1k451 \leq k \leq 45 we let pkp_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=145kpk\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 10610^{-6}.

예제

예제 1

입력
A9Q22T5
출력
19.88129713423831

예제 2

입력
JQQQKKK
출력
20.91314505643106
코드를 제출하려면 로그인하세요.