結果

問題 No.108 トリプルカードコンプ
ユーザー kkktymkkktym
提出日時 2019-08-07 13:48:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 58,988 KB
実行使用メモリ 13,788 KB
最終ジャッジ日時 2023-09-25 22:39:04
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 10 ms
13,756 KB
testcase_08 AC 5 ms
13,632 KB
testcase_09 AC 5 ms
13,640 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstdio>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
int n;
int a[110];
double dp[110][110][110];
double rec(int i,int j,int k){
  if(dp[i][j][k] >= 0) return dp[i][j][k];
  int sum = i + j + k;
  double res = 0;

  if(i != 0) res += (double)i/sum * rec(i-1,j,k);
  if(j != 0) res += (double)j/sum * rec(i+1,j-1,k);
  if(k != 0) res += (double)k/sum * rec(i,j+1,k-1);
  res += (double)n/sum;

  return dp[i][j][k] = res;
}
int main()
{
  cin >> n;
  rep(i,n) cin >> a[i];

  rep(i,n+1) rep(j,n+1) rep(k,n+1) dp[i][j][k] = -1;
  dp[0][0][0] = 0;

  int one = 0,two = 0,thr = 0;
  rep(i,n){
    int x = max( 3-a[i] , 0 );
    if(x==1) one++;
    else if(x==2) two++;
    else thr++;
  }
  
  printf("%.7f\n", rec(one,two,thr));

  
  return 0;
}
0