結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-01-20 17:22:50 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 762 ms / 5,000 ms |
| コード長 | 1,604 bytes |
| コンパイル時間 | 133 ms |
| コンパイル使用メモリ | 13,056 KB |
| 実行使用メモリ | 52,096 KB |
| 最終ジャッジ日時 | 2024-07-02 22:47:30 |
| 合計ジャッジ時間 | 3,885 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def main():
n = II()
aa = LI()
c0 = c1 = c2 = 0
for a in aa:
if a == 0: c0 += 1
if a == 1: c1 += 1
if a == 2: c2 += 1
# dp[i][j][k]…0枚なのがi種類、1枚なのがj種類、2枚なのがk種類のとき、あと何回引くかの期待値
dp = [[[0] * (c0 + c1 + c2 + 1) for _ in range(c0 + c1 + 1)] for _ in range(c0 + 1)]
for i in range(c0 + 1):
for j in range(c0 + c1 + 1):
for k in range(c0 + c1 + c2 + 1):
if (i, j, k) == (0, 0, 0): continue
v = n
if i - 1 >= 0 and j + 1 <= c0 + c1: v += dp[i - 1][j + 1][k] * i
if j - 1 >= 0 and k + 1 <= c0 + c1 + c2: v += dp[i][j - 1][k + 1] * j
if k - 1 >= 0: v += dp[i][j][k - 1] * k
dp[i][j][k] = v / (i + j + k)
print(dp[c0][c1][c2])
main()
# dp[7][5][3] dp[6][6][3] dp[7][4][4] dp[7][5][2]
mkawa2