結果

問題 No.108 トリプルカードコンプ
ユーザー chocorusk
提出日時 2019-05-28 12:58:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,107 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 98,956 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-09-17 15:38:40
合計ジャッジ時間 1,439 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
double memo[101][101][101];
double solve(int x, int y, int z){
    if(x==0 && y==0 && z==0) return 0;
    if(memo[x][y][z]) return memo[x][y][z];
    double ret=(double)n/(double)(x+y+z);
    if(x) ret+=(double)x/(double)(x+y+z)*solve(x-1, y+1, z);
    if(y) ret+=(double)y/(double)(x+y+z)*solve(x, y-1, z+1);
    if(z) ret+=(double)z/(double)(x+y+z)*solve(x, y, z-1);
    return memo[x][y][z]=ret;
}
int main()
{
    cin>>n;
    int a[110];
    int x=0, y=0, z=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==0) x++;
        else if(a[i]==1) y++;
        else if(a[i]==2) z++;
    }
    printf("%.7lf\n", solve(x, y, z));
    return 0;
}
0