結果

問題 No.162 8020運動
ユーザー 👑 kmjpkmjp
提出日時 2015-02-09 02:36:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,716 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 144,820 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 20:36:44
合計ジャッジ時間 4,457 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 49 ms
4,376 KB
testcase_02 AC 73 ms
4,500 KB
testcase_03 AC 97 ms
4,376 KB
testcase_04 AC 97 ms
4,380 KB
testcase_05 AC 98 ms
4,380 KB
testcase_06 AC 97 ms
4,376 KB
testcase_07 AC 97 ms
4,376 KB
testcase_08 AC 97 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 73 ms
4,376 KB
testcase_11 AC 49 ms
4,380 KB
testcase_12 AC 24 ms
4,380 KB
testcase_13 AC 97 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 29 ms
4,376 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 92 ms
4,376 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 78 ms
4,380 KB
testcase_21 AC 78 ms
4,376 KB
testcase_22 AC 73 ms
4,380 KB
testcase_23 AC 79 ms
4,376 KB
testcase_24 AC 72 ms
4,376 KB
testcase_25 AC 83 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 54 ms
4,376 KB
testcase_28 AC 93 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

double memo[70][20];
int P[3];

// N本の歯がY年後に何本残るか?
double func(int Y, int N) {
	
	// おめでとうございます。80歳までN本残りました。
	if(Y == 0)
		return N;
	
	// メモ参照
	if(memo[Y][N] >= 0)
		return memo[Y][N];
	
	if(N == 1) {
		// 歯が1本の時は確率が独特なので、別処理した方が楽です。
		// 1年残る確率×(Y-1)年残る確率
		memo[Y][N] = (100-P[0])/100.0 * func(Y-1, 1);
	}
	else {
		memo[Y][N] = 0;
		// 歯の壊れ方を2**N通り試す
		for(int mask=0; mask < 1<<N; mask++) {
			//この壊れ方をする確率は?
			double prob=1;
			for(int i = 0; i < N; i++) {
				double bad;
				if(i==0 || i==N-1) //両端だけ確率が異なる
					bad = P[1]/100.0;
				else //両端以外
					bad = P[2]/100.0;
				
				if(mask & (1<<i)) //歯が残る
					prob *= 1-bad;
				else //残念虫歯でした
					prob *= bad;
			}
			
			//連続する歯の残り方は?
			int left=0;
			for(int i = 0; i < N; i++) {
				if(mask & (1<<i)) {
					//残っている歯が連続している
					left++;
				}
				else {
					//虫歯で残った歯が途切れた
					if(left > 0)
						memo[Y][N] += prob * func(Y-1,left);
					left = 0;
				}
			}
			
			if(left > 0)
				memo[Y][N] += prob * func(Y-1,left);
		}
	}
	
	return memo[Y][N];
}

int main(int argc,char** argv){
	int x,y,T;
	
	cin >> T;
	cin >> P[0] >> P[1] >> P[2];
	
	// メモ初期化
	for(x = 0; x < 70; x++)
		for(y = 0; y < 20; y++)
			memo[x][y] = -1;
	
	// 上の歯と下の歯の期待値は同じなので、片方を求めて2倍すればよい
	printf("%.9lf\n" , 2 * func(80-T, 14));
	
	return 0;
}
0