結果

問題 No.162 8020運動
ユーザー yyyuuuummmmaaa1
提出日時 2019-08-03 12:54:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 1,241 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 167,204 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 16:41:23
合計ジャッジ時間 5,017 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using ld=long double;

ld A,B,C;
#define WHATS(var) //cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
vector<vector<ld>>memo(21,vector<ld>(15,-2));
ld solve(int T,int X){
	if(memo[T][X]<-1){
		if(T==0){
			memo[T][X]=X;
		}else if(X==0){
			memo[T][X]=0;
		}else{
			memo[T][X]=0;
			for(int i=0;i<(1<<X);++i){
				ld per=1;
				for(int j=0;j<X;++j){
					if(X==1){
						if(i&(1<<j)){
							per*=1-A;
						}else{
							per*=A;
						}
					}else if(j==0||j==X-1){
						if(i&(1<<j)){
							per*=1-B;
						}else{
							per*=B;
						}
					}else{
						if(i&(1<<j)){
							per*=1-C;
						}else{
							per*=C;
						}
					}
				}
				WHATS(per);
				vector<int>ns;
				int num=0;
				for(int j=0;j<X;++j){
					if(i&(1<<j)){
						num++;
					}else{
						if(num)ns.push_back(num);
						num=0;
					}
				}
				if(num)ns.push_back(num);
				num=0;

				ld sum=0;
				for(auto n:ns){
					sum+=solve(T-1,n);
				}
				memo[T][X]+=sum*per;
			}
		}
	}
	return memo[T][X];
}

int main() {
	ios::sync_with_stdio(false);
	ld age;
	cin>>age>>A>>B>>C;
	A/=100;
	B/=100;
	C/=100;
	cout<<setprecision(10)<<fixed;
	ld answer=2*solve(80-age,14);
	cout<<answer<<endl;
	return 0;
}
0