結果

問題 No.76 回数の期待値で練習
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-21 09:56:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 144,100 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-29 03:12:36
合計ジャッジ時間 1,685 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
18,864 KB
testcase_01 AC 24 ms
19,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main(){

    long double tot=0;
    vector<long double> p(7), dp(1000001), s = {0.0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235};
    for (int i=1; i<=5; i++){
        tot = s[i+1]-1;
        for (int j=1; j<i; j++) tot -= s[i-j+1] * p[j];
        p[i] = tot;
    }

    p[6] = 1;
    for (int i=1; i<=5; i++) p[6] -= p[i];
    for (int i=1; i<=1000000; i++){
        dp[i] = 1;
        for (int j=1; j<=6; j++){
            if (i-j >= 0) dp[i] += dp[i-j] *  p[j];
        }
    }

    long long T, N;
    cin >> T;
    for (int i=0; i<T; i++){
        cin >> N;
        cout << setprecision(18) << dp[N] << endl;
    }

    return 0;
}
0