結果

問題 No.108 トリプルカードコンプ
ユーザー ctyl_0ctyl_0
提出日時 2015-10-06 03:23:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,522 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 86,700 KB
実行使用メモリ 7,896 KB
最終ジャッジ日時 2023-09-27 07:30:50
合計ジャッジ時間 1,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
typedef long long ll;
using namespace std;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;


int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

double dp[101][101][101]; // 0
int N;

double dfs(int i, int j, int k){
    if (dp[i][j][k] != 0) {
        return dp[i][j][k];
    }
    int sum = i + j + k;
    if (sum == 0) {
        return dp[i][j][k] = 0;
    }
    
    double ret = 0;
    
    if (i > 0) ret += dfs(i - 1, j + 1, k) * i;
    if (j > 0) ret += dfs(i, j - 1, k + 1) * j;
    if (k > 0) ret += dfs(i, j, k - 1) * k;
    ret += N;
    ret /= sum;
    
    return dp[i][j][k] = ret;
}

int main() {
    // source code
    
    N = inputValue(); // 100
    vector<int> A(N); // 10 3以上は無視
    vector<int> R(3, 0); // 0枚のカード数, 1枚, 2枚
    rep(i, N){
        A[i] = inputValue();
        if (A[i] < 3) {
            R[A[i]]++;
        }
    }
    
    output(dfs(R[0], R[1], R[2]), 10);

    
    return 0;
}
0