結果

問題 No.1688 Veterinarian
ユーザー gr1msl3y
提出日時 2022-02-24 00:00:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 937 ms / 3,000 ms
コード長 899 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 132,496 KB
最終ジャッジ日時 2024-07-02 00:09:18
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

A, B, C, N = map(int, input().split())
X = [A, B, C]
dp = {(A, B, C): 1.0}
for _ in range(N):
    ndp = {}
    for a, b, c in dp:
        s = a+b+c
        if a > 1:
            if (a-1, b, c) not in ndp:
                ndp[(a-1, b, c)] = 0.0
            ndp[(a-1, b, c)] += dp[(a, b, c)]*a*(a-1)/s/(s-1)
        if b > 1:
            if (a, b-1, c) not in ndp:
                ndp[(a, b-1, c)] = 0.0
            ndp[(a, b-1, c)] += dp[(a, b, c)]*b*(b-1)/s/(s-1)
        if c > 1:
            if (a, b, c-1) not in ndp:
                ndp[(a, b, c-1)] = 0.0
            ndp[(a, b, c-1)] += dp[(a, b, c)]*c*(c-1)/s/(s-1)
        if (a, b, c) not in ndp:
            ndp[(a, b, c)] = 0.0
        ndp[(a, b, c)] += dp[(a, b, c)] * \
            (s*(s-1)-a*(a-1)-b*(b-1)-c*(c-1))/s/(s-1)
    dp = ndp

ans = [0.0]*3
for t in dp:
    for i in range(3):
        ans[i] += dp[t]*(X[i]-t[i])

print(*ans)
0