結果

問題 No.1688 Veterinarian
ユーザー zezerozezero
提出日時 2021-09-25 03:19:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 1,465 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 106,256 KB
実行使用メモリ 57,564 KB
最終ジャッジ日時 2023-09-18 22:47:40
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
5,812 KB
testcase_07 AC 5 ms
4,556 KB
testcase_08 AC 96 ms
57,564 KB
testcase_09 AC 90 ms
55,412 KB
testcase_10 AC 14 ms
12,200 KB
testcase_11 AC 12 ms
9,780 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 5 ms
6,156 KB
testcase_14 AC 3 ms
4,604 KB
testcase_15 AC 9 ms
8,620 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

double dp[52][52][52][52];

int choose(int x){return x*(x-1)/2;}

int main(){
    int A,B,C,N;
    cin >> A >> B >> C >> N;
    dp[0][A][B][C] = 1.0;
    for (int n = 0; n < N;n++){
        for (int a = 1; a <= A;a++){
            for (int b = 1; b <= B;b++){
                for (int c = 1; c <= C;c++){
                    int ex = choose(a+b+c)-choose(a)-choose(b)-choose(c);
                    int all = choose(a+b+c);
                    dp[n+1][a-1][b][c] += choose(a)*dp[n][a][b][c]/all;
                    dp[n+1][a][b-1][c] += choose(b)*dp[n][a][b][c]/all;
                    dp[n+1][a][b][c-1] += choose(c)*dp[n][a][b][c]/all;
                    dp[n+1][a][b][c] += ex*dp[n][a][b][c]/all; 
                }
            }
        }
    }
    double ansa = 0.0,ansb = 0.0,ansc = 0.0;
    for (int i = 1; i <= A;i++){
        for (int j = 1; j <= B;j++){
            for (int k = 1; k <= C;k++){
                ansa += dp[N][i][j][k]*(A-i);
                ansb += dp[N][i][j][k]*(B-j);
                ansc += dp[N][i][j][k]*(C-k);
            }
        }
    }
    cout << fixed << setprecision(10);
    cout << ansa << " " << ansb << " " << ansc << endl;
    

    return 0;
}
0