結果

問題 No.1688 Veterinarian
ユーザー milanis48663220milanis48663220
提出日時 2021-09-24 22:10:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 3,000 ms
コード長 2,129 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 116,636 KB
実行使用メモリ 49,920 KB
最終ジャッジ日時 2023-09-18 21:27:53
合計ジャッジ時間 1,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,464 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 63 ms
49,920 KB
testcase_09 AC 61 ms
47,744 KB
testcase_10 AC 17 ms
15,468 KB
testcase_11 AC 8 ms
9,068 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 6 ms
7,140 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 15 ms
12,792 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

double dpa[55][55][55][55];
double dpb[55][55][55][55];
double dpc[55][55][55][55];
bool ok[55][55][55][55];

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

void calc(int a, int b, int c, int n){
    if(a+b+c <= 1) return;
    if(n == 0) return;
    if(ok[a][b][c][n]) return;
    double pa = (cb2(a)/cb2(a+b+c));
    double pb = (cb2(b)/cb2(a+b+c));
    double pc = (cb2(c)/cb2(a+b+c));
    if(a > 1){
        calc(a-1, b, c, n-1);
        dpa[a][b][c][n] += pa+dpa[a-1][b][c][n-1]*pa;
        dpb[a][b][c][n] += dpb[a-1][b][c][n-1]*pa;
        dpc[a][b][c][n] += dpc[a-1][b][c][n-1]*pa;
    }
    if(b > 1){
        calc(a, b-1, c, n-1);
        dpa[a][b][c][n] += dpa[a][b-1][c][n-1]*pb;
        dpb[a][b][c][n] += pb+dpb[a][b-1][c][n-1]*pb;
        dpc[a][b][c][n] += dpc[a][b-1][c][n-1]*pb;
    }
    if(c > 1){
        calc(a, b, c-1, n-1);
        dpa[a][b][c][n] += dpa[a][b][c-1][n-1]*pc;
        dpb[a][b][c][n] += dpb[a][b][c-1][n-1]*pc;
        dpc[a][b][c][n] += pc+dpc[a][b][c-1][n-1]*pc;
    }
    calc(a, b, c, n-1);
    double p = 1.0-(pa+pb+pc);
    dpa[a][b][c][n] += dpa[a][b][c][n-1]*p;
    dpb[a][b][c][n] += dpb[a][b][c][n-1]*p;
    dpc[a][b][c][n] += dpc[a][b][c][n-1]*p;
    ok[a][b][c][n] = true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    calc(a, b, c, n);
    cout << dpa[a][b][c][n] << ' ' << dpb[a][b][c][n] << ' ' << dpc[a][b][c][n] << endl;
}
0