結果

問題 No.1688 Veterinarian
ユーザー rogi52rogi52
提出日時 2022-10-15 07:07:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 576 ms / 3,000 ms
コード長 1,686 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 207,988 KB
実行使用メモリ 110,172 KB
最終ジャッジ日時 2023-09-09 02:14:10
合計ジャッジ時間 5,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,348 KB
testcase_01 AC 3 ms
6,344 KB
testcase_02 AC 3 ms
6,344 KB
testcase_03 AC 3 ms
6,396 KB
testcase_04 AC 3 ms
6,412 KB
testcase_05 AC 4 ms
6,896 KB
testcase_06 AC 4 ms
6,900 KB
testcase_07 AC 119 ms
110,172 KB
testcase_08 AC 576 ms
110,172 KB
testcase_09 AC 529 ms
105,136 KB
testcase_10 AC 39 ms
19,512 KB
testcase_11 AC 54 ms
30,144 KB
testcase_12 AC 18 ms
19,108 KB
testcase_13 AC 6 ms
8,448 KB
testcase_14 AC 16 ms
15,940 KB
testcase_15 AC 24 ms
12,444 KB
testcase_16 AC 6 ms
7,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

template < class T >
vector< vector< T > > bicoef_table(int N) {
    vector< vector< T > > table(N + 1, vector< T >(N + 1));
    table[0][0] = 1;
    for(int i = 1; i <= N; i++) {
        table[i][0] = 1;
        for(int j = 1; j <= N; j++) {
            table[i][j] = table[i - 1][j - 1] + table[i - 1][j];
        }
    }
    return table;
}

using ld = long double;
ld dp[51][51][51][51] = {0.0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int A,B,C,N; cin >> A >> B >> C >> N;
    dp[A][B][C][0] = 1.0;

    auto bt = bicoef_table<ld>(200);
    auto comb = [bt](int N, int K) {
        if(N < K) return ld(0.0);
        return bt[N][K];
    };

    for(int n = 0; n < N; n++)
        for(int a = A; a >= 0; a--)
            for(int b = B; b >= 0; b--)
                for(int c = C; c >= 0; c--) if(a + b + c > 1) {
                    if(a) dp[a - 1][b][c][n + 1] += dp[a][b][c][n] * comb(a, 2) / comb(a + b + c, 2);
                    if(b) dp[a][b - 1][c][n + 1] += dp[a][b][c][n] * comb(b, 2) / comb(a + b + c, 2);
                    if(c) dp[a][b][c - 1][n + 1] += dp[a][b][c][n] * comb(c, 2) / comb(a + b + c, 2);
                    dp[a][b][c][n + 1] += dp[a][b][c][n] * (1.0 - (comb(a, 2) + comb(b, 2) + comb(c, 2)) / comb(a + b + c, 2));
                }

    ld EA = 0, EB = 0, EC = 0;
    rep(a,A+1)rep(b,B+1)rep(c,C+1) {
        EA += (A - a) * dp[a][b][c][N];
        EB += (B - b) * dp[a][b][c][N];
        EC += (C - c) * dp[a][b][c][N];
    }
    cout << fixed << setprecision(20) << EA << " " << EB << " " << EC << endl;
}
0