結果

問題 No.1688 Veterinarian
ユーザー tktk_snsn
提出日時 2021-09-24 22:44:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 777 ms / 3,000 ms
コード長 1,113 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 159,088 KB
最終ジャッジ日時 2024-07-05 11:03:56
合計ジャッジ時間 7,651 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

U = 50
A, B, C, N = map(int, input().split())

# dp[i,j,k]: (i,j,k)枚もってる確率
dp = [[[0] * (U + 1) for _ in range(U + 1)] for _ in range(U + 1)]
dp[A][B][C] = 1.0

for _ in range(N):
    ndp = [[[0] * (U + 1) for _ in range(U + 1)] for _ in range(U + 1)]
    for a in range(U+1):
        for b in range(U+1):
            for c in range(U+1):
                tot = a + b + c
                tot = tot * (tot - 1) // 2
                if tot == 0:
                    continue

                pa = a * (a - 1) // 2 / tot
                ndp[a-1][b][c] += dp[a][b][c] * pa

                pb = b * (b - 1) // 2 / tot
                ndp[a][b-1][c] += dp[a][b][c] * pb

                pc = c * (c - 1) // 2 / tot
                ndp[a][b][c-1] += dp[a][b][c] * pc

                ndp[a][b][c] += dp[a][b][c] * (1 - pa - pb - pc)
    dp = ndp

x, y, z = 0, 0, 0
for a in range(U+1):
    for b in range(U+1):
        for c in range(U+1):
            x += (A - a) * dp[a][b][c]
            y += (B - b) * dp[a][b][c]
            z += (C - c) * dp[a][b][c]

print("{:.12f} {:.12f} {:.12f}".format(x, y, z))
0