結果
問題 | No.1151 チャレンジゲーム |
ユーザー |
![]() |
提出日時 | 2020-08-07 22:46:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 1,769 bytes |
コンパイル時間 | 2,568 ms |
コンパイル使用メモリ | 205,432 KB |
最終ジャッジ日時 | 2025-01-12 17:34:47 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#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; }