結果

問題 No.76 回数の期待値で練習
ユーザー kazumakazuma
提出日時 2018-12-27 20:30:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,014 ms / 5,000 ms
コード長 445 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 197,000 KB
実行使用メモリ 33,172 KB
最終ジャッジ日時 2024-04-09 03:06:15
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1,014 ms
33,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ld = long double;

ld p[] = { 1.0 / 12, 1.0 / 6, 1.0 / 4, 1.0 / 12, 1.0 / 4, 1.0 / 6 };

int main()
{
	cout << fixed << setprecision(6);
	int T;
	cin >> T;
	while (T--) {
		int N;
		cin >> N;
		vector<ld> dp(N);
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 1; j <= 6; j++) {
				dp[i] += ((i + j >= N ? 0 : dp[i + j]) + 1) * p[j - 1];
			}
		}
		cout << dp[0] << endl;
	}
	return 0;
}
0