結果

問題 No.108 トリプルカードコンプ
ユーザー imgry22imgry22
提出日時 2015-01-25 00:59:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,554 bytes
コンパイル時間 3,420 ms
コンパイル使用メモリ 144,244 KB
実行使用メモリ 11,688 KB
最終ジャッジ日時 2023-09-05 04:47:23
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 10 ms
11,688 KB
testcase_08 AC 6 ms
11,684 KB
testcase_09 AC 6 ms
11,484 KB
testcase_10 AC 6 ms
11,472 KB
testcase_11 AC 6 ms
11,476 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
6,560 KB
testcase_14 AC 3 ms
6,616 KB
testcase_15 AC 3 ms
6,660 KB
testcase_16 AC 3 ms
6,612 KB
testcase_17 AC 3 ms
6,460 KB
testcase_18 AC 8 ms
11,384 KB
testcase_19 AC 7 ms
10,960 KB
testcase_20 AC 6 ms
11,544 KB
testcase_21 AC 7 ms
11,676 KB
testcase_22 AC 5 ms
11,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000.0
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 100;
int N;
int A[MAX_N];
int card[3];
double dp[MAX_N+1][MAX_N+1][MAX_N+1];

double solve(int x, int y, int z)
{
  if(dp[x][y][z] >= 0) return dp[x][y][z];
  if(x + y + z <= 0) return dp[x][y][z] = 0.0;

  double res = (double)N / (x + y + z);

  if(x > 0) res += solve(x - 1, y + 1, z    ) * x / (x + y + z);
  if(y > 0) res += solve(x,     y - 1, z + 1) * y / (x + y + z);
  if(z > 0) res += solve(x,     y,     z - 1) * z / (x + y + z);

  return dp[x][y][z] = res;
}

int main()
{
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) rep(j, 3) if(A[i] == j) card[j] += 1;

  erep(i, 0, N) erep(j, 0, N) erep(k, 0, N) dp[i][j][k] = -INF;

  printf("%.10f\n",  solve(card[0], card[1], card[2]));

  return 0;
}
0