結果

問題 No.1688 Veterinarian
ユーザー tentententen
提出日時 2022-07-27 10:47:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 315 ms / 3,000 ms
コード長 2,666 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 74,664 KB
実行使用メモリ 118,400 KB
最終ジャッジ日時 2023-09-23 17:23:03
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
53,800 KB
testcase_01 AC 88 ms
53,732 KB
testcase_02 AC 87 ms
52,880 KB
testcase_03 AC 87 ms
53,952 KB
testcase_04 AC 86 ms
55,868 KB
testcase_05 AC 87 ms
53,812 KB
testcase_06 AC 89 ms
54,028 KB
testcase_07 AC 111 ms
55,172 KB
testcase_08 AC 315 ms
118,400 KB
testcase_09 AC 275 ms
117,948 KB
testcase_10 AC 116 ms
57,120 KB
testcase_11 AC 105 ms
57,504 KB
testcase_12 AC 87 ms
53,040 KB
testcase_13 AC 95 ms
52,792 KB
testcase_14 AC 93 ms
52,836 KB
testcase_15 AC 125 ms
55,752 KB
testcase_16 AC 89 ms
53,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int n = sc.nextInt();
        double[][][][] dp = new double[n + 1][a + 1][b + 1][c + 1];
        dp[0][a][b][c] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = a; j >= 0; j--) {
                for (int k = b; k >= 0; k--) {
                    for (int l = c; l >= 0 && dp[i][j][k][l] > 0; l--) {
                        double sum = j + k + l;
                        double remain = 1;
                        if (j > 1) {
                            dp[i + 1][j - 1][k][l] += dp[i][j][k][l] * j * (j - 1) / sum / (sum - 1);
                            remain -= j * (j - 1) / sum / (sum - 1);
                        }
                        if (k > 1) {
                            dp[i + 1][j][k - 1][l] += dp[i][j][k][l] * k * (k - 1) / sum / (sum - 1);
                            remain -= k * (k - 1) / sum / (sum - 1);
                        }
                        if (l > 1) {
                            dp[i + 1][j][k][l - 1] += dp[i][j][k][l] * l * (l - 1) / sum / (sum - 1);
                            remain -= l * (l - 1) / sum / (sum - 1);
                        }
                        dp[i + 1][j][k][l] += dp[i][j][k][l] * remain;
                    }
                }
            }
        }
        double ansA = 0;
        double ansB = 0;
        double ansC = 0;
        for (int i = a; i >= 0; i--) {
            for (int j = b; j >= 0; j--) {
                for (int k = c; k >= 0; k--) {
                    ansA += (a - i) * dp[n][i][j][k];
                    ansB += (b - j) * dp[n][i][j][k];
                    ansC += (c - k) * dp[n][i][j][k];
                }
            }
        }
        System.out.println(ansA + " " + ansB + " " + ansC);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0