結果
問題 |
No.76 回数の期待値で練習
|
ユーザー |
![]() |
提出日時 | 2016-11-05 14:29:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 5,000 ms |
コード長 | 493 bytes |
コンパイル時間 | 1,686 ms |
コンパイル使用メモリ | 167,636 KB |
実行使用メモリ | 90,648 KB |
最終ジャッジ日時 | 2024-11-25 03:08:57 |
合計ジャッジ時間 | 2,144 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; int Q, N; bool vis[1000009]; double dp[1000009]; double r[] = { 1.0 / 12, 1.0 / 6, 1.0 / 4, 1.0 / 12, 1.0 / 4, 1.0 / 6 }; double rec(int x) { if(x <= 0) return 0.0; if(vis[x]) return dp[x]; double ret = 0.0; for(int i = 1; i <= 6; i++) ret += rec(x - i) * r[i - 1]; vis[x] = true; return dp[x] = ret + 1; } int main() { rec(1000000); cin >> Q; while(Q--) { cin >> N; cout << fixed << setprecision(15) << dp[N] << endl; } return 0; }