結果

問題 No.108 トリプルカードコンプ
ユーザー togatogatogatoga
提出日時 2015-08-25 00:28:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,280 bytes
コンパイル時間 1,200 ms
コンパイル使用メモリ 144,072 KB
実行使用メモリ 14,032 KB
最終ジャッジ日時 2023-09-25 16:50:23
合計ジャッジ時間 2,493 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,872 KB
testcase_01 AC 5 ms
14,024 KB
testcase_02 AC 6 ms
13,924 KB
testcase_03 AC 5 ms
13,868 KB
testcase_04 AC 6 ms
13,960 KB
testcase_05 AC 5 ms
14,016 KB
testcase_06 AC 5 ms
13,920 KB
testcase_07 AC 9 ms
13,972 KB
testcase_08 AC 6 ms
14,028 KB
testcase_09 AC 5 ms
13,868 KB
testcase_10 AC 5 ms
13,960 KB
testcase_11 AC 5 ms
13,960 KB
testcase_12 AC 5 ms
14,024 KB
testcase_13 AC 6 ms
14,024 KB
testcase_14 AC 5 ms
13,868 KB
testcase_15 AC 5 ms
13,900 KB
testcase_16 AC 6 ms
13,864 KB
testcase_17 AC 6 ms
13,960 KB
testcase_18 AC 9 ms
14,032 KB
testcase_19 AC 6 ms
13,888 KB
testcase_20 AC 5 ms
13,860 KB
testcase_21 AC 7 ms
13,880 KB
testcase_22 AC 6 ms
13,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;
typedef    pair<long,long>    pll;

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 100000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N;
double dp[110][110][110];

double memo(int two, int one, int zero){
  if (dp[two][one][zero] >= 0){
    return dp[two][one][zero];
  }
  if (two == 0 && one == 0 && zero == 0){
    return 0.0;
  }
  double res = N * 1.0 / (two + one + zero);
  if (two > 0){
    res += memo(two - 1, one, zero) * two / (two + one + zero);
  }
  if (one > 0){
    res += memo(two + 1, one -1, zero) * one / (two + one + zero);
  }
  if (zero > 0){
    res += memo(two, one + 1, zero - 1) * zero / (two + one + zero);
  }
  return dp[two][one][zero] = res;
}

int main(){
  cin >> N;
  int two,one,zero;
  two = one = zero = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if (x == 0){
      zero++;
    }else if(x == 1){
      one++;
    }else if(x == 2){
      two++;
    }
  }
  memset(dp, -1, sizeof(dp));
  printf("%.20lf\n", memo(two, one, zero));
}
0