結果

問題 No.567 コンプリート
ユーザー tubo28
提出日時 2017-09-08 23:49:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 166,292 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-14 15:11:54
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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

double dp[1000][1<<6];
int n;

double rec(int k, int S) {
    double &res = dp[k][S];
    if (res != -1) {
        return res;
    }
    if (k == 0) {
        res = (S == 0) ? 1 : 0;
    } else if (S == 0) {
        res = 1;
    } else {
        res = 0;
        for (int i = 0; i < 6; ++i) {
            res += 1./6 * rec(k - 1, S & ~(1 << i));
        }
    }
    // cout << bitset<6>(S) << ' ' << k << ' ' << res << endl;
    return res;
}

int main() {
    while (cin >> n) {
        double ans;
        if (n > 500) {
            ans = 1;
        } else {
            fill((double*)begin(dp), (double*)end(dp), -1);
            ans = rec(n, 63);
        }
        printf("%.10lf\n", ans);
    }
}
0