結果

問題 No.1688 Veterinarian
ユーザー planesplanes
提出日時 2021-09-25 03:06:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 584 ms / 3,000 ms
コード長 1,931 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 176,600 KB
実行使用メモリ 169,216 KB
最終ジャッジ日時 2023-09-18 22:47:30
合計ジャッジ時間 4,270 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 23 ms
14,836 KB
testcase_08 AC 584 ms
169,216 KB
testcase_09 AC 524 ms
157,612 KB
testcase_10 AC 24 ms
16,884 KB
testcase_11 AC 30 ms
20,656 KB
testcase_12 AC 4 ms
5,048 KB
testcase_13 AC 3 ms
4,652 KB
testcase_14 AC 6 ms
6,220 KB
testcase_15 AC 17 ms
13,260 KB
testcase_16 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

struct bag{double a,b,c;};

int main() {
    double A,B,C,N;cin>>A>>B>>C>>N;
    vector<vector<vector<vector<bag>>>> dp(A+1,vector<vector<vector<bag>>> (B+1,vector<vector<bag>> (C+1,vector<bag> (N+1))));
    for(ll i=0;i<=A;i++) {
        for(ll j=0;j<=B;j++) {
            for(ll h=0;h<=C;h++) {
                dp[i][j][h][0]={0,0,0};
            }
        }
    }

    for(ll i=1;i<=N;i++) {
        for(ll j=0;j<=A;j++) {
            for(ll h=0;h<=B;h++) {
                for(ll k=0;k<=C;k++) {
                double all=(j+h+k)*(j+h+k-1)/2;
                double x=j*(j-1)/2;
                double y=h*(h-1)/2;
                double z=k*(k-1)/2;

               bag ans{0,0,0};
                if(j>1) {
                    ans.a+=(dp[j-1][h][k][i-1].a+1)*x/all;
                    ans.b+=dp[j-1][h][k][i-1].b*x/all;
                    ans.c+=dp[j-1][h][k][i-1].c*x/all;
                }
                if(h>1) {
                    ans.a+=dp[j][h-1][k][i-1].a*y/all;
                    ans.b+=(dp[j][h-1][k][i-1].b+1)*y/all;
                    ans.c+=dp[j][h-1][k][i-1].c*y/all;
                }
                if(k>1) {
                    ans.a+=dp[j][h][k-1][i-1].a*z/all;
                    ans.b+=dp[j][h][k-1][i-1].b*z/all;
                    ans.c+=(dp[j][h][k-1][i-1].c+1)*z/all;
                }
               double t=all-x-y-z;
               if(t>0) {
                   ans.a+=dp[j][h][k][i-1].a*t/all;
                   ans.b+=dp[j][h][k][i-1].b*t/all;
                   ans.c+=dp[j][h][k][i-1].c*t/all;
               }
                dp[j][h][k][i]=ans;
                }
            }
        }
    }

bag ans=dp[A][B][C][N];
cout<<fixed<<setprecision(10);
cout<<ans.a<<" "<<ans.b<<" "<<ans.c<<endl;
}

0