結果

問題 No.108 トリプルカードコンプ
ユーザー batsumarubatsumaru
提出日時 2019-09-04 21:14:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,191 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 173,428 KB
実行使用メモリ 11,632 KB
最終ジャッジ日時 2023-08-28 14:59:35
合計ジャッジ時間 2,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 12 ms
11,472 KB
testcase_08 AC 8 ms
11,424 KB
testcase_09 AC 8 ms
11,536 KB
testcase_10 AC 7 ms
11,496 KB
testcase_11 AC 8 ms
11,476 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 10 ms
10,864 KB
testcase_19 AC 7 ms
10,372 KB
testcase_20 AC 8 ms
11,632 KB
testcase_21 AC 10 ms
11,584 KB
testcase_22 AC 7 ms
10,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll n;
vector<vector<vector<double>>> dp;

double rec(ll i, ll j, ll k){
  if(i==0 && j==0 && k==0) return 0;
  if(dp[i][j][k]>0) return dp[i][j][k];
  double a=0,b=0,c=0;
  if(i>0){
    a = rec(i-1,j+1,k);
    dp[i-1][j+1][k] = a;
  }
  if(j>0){
    b = rec(i,j-1,k+1);
    dp[i][j-1][k+1] = b;
  }
  if(k>0){
    c = rec(i,j,k-1);
    dp[i][j][k-1] = c;
  }
  return 1.0*(n+i*a+j*b+k*c)/(i+j+k);
}

int main(){
  cin >> n;
  vector<ll> cnt(4,0);
  REP(i,n){
    ll a; cin >> a;
    a = min(a,3LL);
    cnt[a]++;
  }
  // dp[i][j][k] = 0枚:i, 1枚:j, 2枚:k 種類からコンプまで必要なカード枚数の期待値
  dp = vector<vector<vector<double>>>(n+1, vector<vector<double>>(n+1, vector<double>(n+1,0.0)));
  cout << fixed << setprecision(10) << rec(cnt[0],cnt[1],cnt[2]) << endl;
}
0