結果

問題 No.1151 チャレンジゲーム
ユーザー 沙耶花沙耶花
提出日時 2020-08-07 22:46:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 213,012 KB
実行使用メモリ 170,540 KB
最終ジャッジ日時 2023-10-25 03:35:42
合計ジャッジ時間 7,329 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
170,540 KB
testcase_01 AC 46 ms
170,356 KB
testcase_02 AC 52 ms
170,540 KB
testcase_03 AC 48 ms
170,356 KB
testcase_04 AC 48 ms
170,540 KB
testcase_05 AC 46 ms
170,540 KB
testcase_06 AC 47 ms
170,540 KB
testcase_07 AC 46 ms
170,540 KB
testcase_08 AC 47 ms
170,540 KB
testcase_09 AC 47 ms
170,540 KB
testcase_10 AC 47 ms
170,540 KB
testcase_11 AC 47 ms
170,540 KB
testcase_12 AC 48 ms
170,540 KB
testcase_13 AC 58 ms
170,540 KB
testcase_14 AC 58 ms
170,540 KB
testcase_15 AC 57 ms
170,540 KB
testcase_16 AC 58 ms
170,540 KB
testcase_17 AC 58 ms
170,540 KB
testcase_18 AC 59 ms
170,540 KB
testcase_19 AC 58 ms
170,540 KB
testcase_20 AC 57 ms
170,540 KB
testcase_21 AC 57 ms
170,540 KB
testcase_22 AC 58 ms
170,540 KB
testcase_23 AC 58 ms
170,540 KB
testcase_24 AC 57 ms
170,540 KB
testcase_25 AC 56 ms
170,540 KB
testcase_26 AC 58 ms
170,540 KB
testcase_27 AC 58 ms
170,540 KB
testcase_28 AC 77 ms
170,540 KB
testcase_29 AC 75 ms
170,540 KB
testcase_30 AC 77 ms
170,540 KB
testcase_31 AC 71 ms
170,540 KB
testcase_32 AC 78 ms
170,540 KB
testcase_33 AC 78 ms
170,540 KB
testcase_34 AC 76 ms
170,540 KB
testcase_35 AC 78 ms
170,540 KB
testcase_36 AC 80 ms
170,540 KB
testcase_37 AC 79 ms
170,540 KB
testcase_38 AC 76 ms
170,540 KB
testcase_39 AC 75 ms
170,540 KB
testcase_40 AC 81 ms
170,540 KB
testcase_41 AC 71 ms
170,540 KB
testcase_42 AC 78 ms
170,540 KB
testcase_43 AC 78 ms
170,540 KB
testcase_44 AC 72 ms
170,540 KB
testcase_45 AC 78 ms
170,540 KB
testcase_46 AC 82 ms
170,540 KB
testcase_47 AC 77 ms
170,540 KB
testcase_48 AC 52 ms
170,356 KB
testcase_49 AC 54 ms
170,540 KB
testcase_50 AC 72 ms
170,540 KB
testcase_51 AC 80 ms
170,540 KB
testcase_52 AC 81 ms
170,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001

int N;
vector<int> A;
vector<vector<double>> P;
int t=  0;
double dp[1024][102][102][2];

double get(int state,int s,int t,int now){
	if(s>=101)return 1.0;
	if(t>=100)return 0.0;
	if(state==(1<<N)-1){
		if(s>t)return 1.0;
		else return 0.0;
	}
	
	//static vector dp(1<<N,vector(102,vector(102,vector<double>(2,-100.0))));
	if(dp[state][s][t][now]>-1.0)return dp[state][s][t][now];

	double ret;
	if(now==0)ret = 0.0;
	else ret = 1.0;
	int ind = 0;
	for(int i=0;i<N;i++){
		if((state>>i)&1)continue;
		double m;
		if(now==0)m=1.0;
		else m = 0.0;
		for(int j=0;j<N;j++){
			if((state>>j)&1)continue;
			double p = P[i][j];
			if(now==0){
				m = min(m,get(state|(1<<i),s+A[i],t,1)*p + get(state|(1<<j),s,t+A[j],0)*(1.0-p));
			}
			else{
				m = max(m,get(state|(1<<i),s,t+A[i],0)*p + get(state|(1<<j),s+A[j],t,1)*(1.0-p));
			}
		}
		//cout<<state<<','<<now<<','<<m<<endl;
		if(now==0)ret = max(ret,m);
		else ret = min(ret,m);
	}
	
	dp[state][s][t][now] = ret;
	return ret;
}

int main(){
	
	for(int i=0;i<1024;i++){
	for(int j=0;j<102;j++){
		for(int k=0;k<102;k++){
			for(int l=0;l<2;l++)dp[i][j][k][l] = -100.0;
		}
	}
}
	
	
	cin>>N;
	A.resize(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	P.resize(N,vector<double>(N,0.0));
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(A[i]==1){
				P[i][j]=1.0;
				continue;
			}
			if(A[j]==1){
				P[i][j]=1.0/A[i];
				continue;
			}
			for(int k=1;k<=1000;k+=2){
				P[i][j] += pow(1.0/(double)A[i],1) * pow(1.0-(1.0/(double)A[i]),k/2) * pow(1.0-(1.0/(double)A[j]),k/2);
			}
		}
	}
	//cout<<'a'<<endl;
	cout<<fixed<<setprecision(10)<<get(0,0,0,0)<<endl;

	return 0;
}
0