結果
問題 | No.1688 Veterinarian |
ユーザー |
![]() |
提出日時 | 2021-09-24 23:41:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,275 ms / 3,000 ms |
コード長 | 1,287 bytes |
コンパイル時間 | 2,489 ms |
コンパイル使用メモリ | 77,864 KB |
実行使用メモリ | 371,332 KB |
最終ジャッジ日時 | 2024-07-05 11:37:29 |
合計ジャッジ時間 | 23,276 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String s[]=bu.readLine().split(" "); int a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]),c=Integer.parseInt(s[2]),n=Integer.parseInt(s[3]); for(int i=0;i<=a;i++) for(int j=0;j<=b;j++) for(int k=0;k<=c;k++) for(int l=0;l<=n;l++) Arrays.fill(dp[i][j][k][l],-1); System.out.printf("%.7f %.7f %.7f\n",calc(a,b,c,n,0),calc(a,b,c,n,1),calc(a,b,c,n,2)); } static double dp[][][][][]=new double[51][51][51][51][3]; static double calc(int a, int b, int c, int n, int k) { if(n==0) return 0.0; else if(dp[a][b][c][n][k]>=0.0) return dp[a][b][c][n][k]; int all=(a+b+c)*(a+b+c-1)/2, sum=a*(a-1)/2+b*(b-1)/2+c*(c-1)/2; double add=calc(a,b,c,n-1,k)*(all-sum)/all; if(a>=2) add+=(calc(a-1,b,c,n-1,k)+ ((k==0)?1:0))*(a*(a-1)/2)/all; if(b>=2) add+=(calc(a,b-1,c,n-1,k)+ ((k==1)?1:0))*(b*(b-1)/2)/all; if(c>=2) add+=(calc(a,b,c-1,n-1,k)+ ((k==2)?1:0))*(c*(c-1)/2)/all; dp[a][b][c][n][k]=add; return add; } }