結果

問題 No.65 回数の期待値の練習
ユーザー Lay_ec
提出日時 2014-11-14 00:19:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 635 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 71,308 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 10:22:55
合計ジャッジ時間 1,881 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>

using namespace std;

int k;
double memo[30];

//x:これまでの和
//k以上になるのに必要な残り回数の期待値を返す
double rec(int x){

	if(memo[x]!=-1) return memo[x];
	if(x>=k) return memo[x]=0.0;

	double res=0.0;
	for(int i=1;i<=6;i++) res+=rec(x+i)/6.0;

	return memo[x]=res+1.0;

}



int main()
{	

	for(int i=0;i<30;i++) memo[i]=-1;

	cin>>k;
	cout<<rec(0)<<endl;

	return 0;
}
0