結果

問題 No.76 回数の期待値で練習
ユーザー antaanta
提出日時 2015-09-26 17:52:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,911 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 76,236 KB
実行使用メモリ 10,848 KB
最終ジャッジ日時 2023-09-26 16:35:36
合計ジャッジ時間 1,184 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:12: warning: iteration 5 invokes undefined behavior [-Waggressive-loop-optimizations]
    x += p[j] * dp[i - j];
         ~~~^
main.cpp:19:44: note: within this loop
 #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
                                         ~~~^~~~~~~~~~
main.cpp:60:3: note: in expansion of macro ‘rer’
   rer(j, 1, 6) if(i - j >= 0)
   ^~~

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }


int main() {
	const int MaxN = 1000000;
	vector<double> dp(MaxN+1);
	dp[1] = 1.0000000000000000;
	dp[2] = 1.0833333333333333;
	dp[3] = 1.2569444444444444;
	dp[4] = 1.5353009259259260;
	dp[5] = 1.6915991512345676;
	dp[6] = 2.0513639724794235;
	double p[6] = {};
	rer(i, 1, 5) {
		//dp[i+1] = 1 + \sum_{j=1}^i p[j] * dp[i+1-j]
		double x = 1;
		rer(j, 1, i-1)
			x += p[j] * dp[i + 1 - j];
		p[i] = dp[i + 1] - x;
//		cerr << "p[" << i << "]: " << p[i] << endl;
	}
	p[6] = 1 - accumulate(p + 1, p + 6, 0.);
	rer(i, 7, MaxN) {
		double x = 1;
		rer(j, 1, 6) if(i - j >= 0)
			x += p[j] * dp[i - j];
		dp[i] = x;
	}
	int T;
	while(~scanf("%d", &T)) {
		int N;
		scanf("%d", &N);
		double ans = dp[N];
		printf("%.10f\n", ans);
	}
	return 0;
}
0