結果
問題 | No.1688 Veterinarian |
ユーザー |
![]() |
提出日時 | 2021-09-25 03:06:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 330 ms / 3,000 ms |
コード長 | 1,931 bytes |
コンパイル時間 | 1,667 ms |
コンパイル使用メモリ | 179,548 KB |
実行使用メモリ | 169,472 KB |
最終ジャッジ日時 | 2024-07-05 11:57:33 |
合計ジャッジ時間 | 2,945 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#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; }