結果

問題 No.108 トリプルカードコンプ
ユーザー motimoti
提出日時 2015-07-25 12:31:13
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,047 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-23 04:49:34
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <iomanip>
#include <cstring>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int N;
double dp[11][11][11];

double solve(int i, int j, int k) {

  if(i < 0 || j < 0 || k < 0) { return 0.0; }

  double& ret = dp[i][j][k];
  if(i == 0 && j == 0 && k == 0) { return ret = 1.0; }

  if(dp[i][j][k] >= 0) { return dp[i][j][k]; }

  ret =  (double)N / (i + j + k); // 自己ループ

  ret += solve(i-1, j+1, k)  * i / (i + j + k);
  ret += solve(i, j-1, k+1)  * j / (i + j + k);
  ret += solve(i, j, k-1)    * k / (i + j + k);

  return ret;
}

int main() {

  memset(dp, -1, sizeof dp);

  cin >> N;
  int cnt0 = 0, cnt1 = 0, cnt2 = 0;
  rep(i, N) {
    int a; cin >> a;
    if(a == 0) { cnt0 ++; }
    if(a == 1) { cnt1 ++; }
    if(a == 2) { cnt2 ++; }
  }

  cout << setprecision(7) << solve(cnt0, cnt1, cnt2) - 1.0 << endl;

  return 0;
}
0