結果

問題 No.76 回数の期待値で練習
ユーザー sugim48sugim48
提出日時 2014-11-24 00:05:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 515 ms / 5,000 ms
コード長 1,310 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 76,404 KB
実行使用メモリ 18,056 KB
最終ジャッジ日時 2023-08-30 22:30:22
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

double e[7] = {0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235};

int main() {
	vector<double> p(7);
	for (int j = 1; j <= 5; j++) {
		double x = e[j + 1] - 1;
		for (int k = 1; k < j; k++)
			x -= p[k] * e[j - k + 1];
		p[j] = x / e[1];
	}
	p[6] = 1 - p[1] - p[2] - p[3] - p[4] - p[5];
	int T; cin >> T;
	while (T--) {
		int N; cin >> N;
		vector<double> dp(N + 1, 1);
		dp[0] = 0;
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= 6; j++) {
				int _i = max(0, i - j);
				dp[i] += p[j] * dp[_i];
			}
		printf("%.10f\n", dp[N]);
	}
}
0