結果

問題 No.75 回数の期待値の問題
ユーザー cielciel
提出日時 2014-11-24 18:58:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 958 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 47,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 22:43:54
合計ジャッジ時間 1,149 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;

//derived from checkio expected-dice
//unfortunately TLE using Python, rewriting in C++11.

double expected(int n, int s, int t){//vector<int> b){
	//perform checkio probably-dice
	vector<double> a(s*(n+1)+1);
	for(int i=1;i<=s;i++)a[i+s]=pow(1.0/s,n);
	for(int e=0;e<n-1;e++)for(int i=s*n;i>=0;i--){
		double sum=0;
		for(int j=i;j<i+s;j++)sum+=a[j];
		a[i+s]=sum;
	}
	int l=t+1; //b.size();
	double ret=0;
	vector<double> p(l);
	p[0]=1;
	//vector<int> nxt(l);
	//for(int i=0;i<l;i++)nxt[i]=(i+b[i]+l)%l;
	for(int z=1;z<400;z++){
		vector<double> pnxt(l);
		for(int x=0;x<l;x++)if(p[x]){
			for(int i=s+1;i<a.size();i++){
				int y=x+i-s;
				//y=nxt[y%l];
				if(y>=l)y=0;
				pnxt[y]+=p[x]*a[i];
			}
		}
		ret+=z*pnxt[t];
		pnxt[t]=0;
		p=pnxt;
	}
	return ret;
}

int main(){
	int N;
	scanf("%d",&N);
	printf("%f\n",expected(1,6,N));
}
0