結果
問題 | No.76 回数の期待値で練習 |
ユーザー |
![]() |
提出日時 | 2022-12-21 09:56:48 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 1,386 ms |
コンパイル使用メモリ | 143,852 KB |
実行使用メモリ | 18,932 KB |
最終ジャッジ日時 | 2024-11-18 02:37:33 |
合計ジャッジ時間 | 1,876 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
ソースコード
#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;}