結果
問題 |
No.1151 チャレンジゲーム
|
ユーザー |
![]() |
提出日時 | 2020-08-07 22:42:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,681 bytes |
コンパイル時間 | 948 ms |
コンパイル使用メモリ | 91,588 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-24 22:57:37 |
合計ジャッジ時間 | 2,642 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 46 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; template <typename T> class OffsetVec{ public: int n; vector<T> v; T& operator[](int x) { return v[x+n]; } void print(){ for(int i = -n; i <= n; i++) cout << v[i+n] << ' '; cout << endl; } OffsetVec(int _n){ n = _n; v = vector<T>(2*n+1); } }; vector<OffsetVec<double>> dp; int N; double A[10]; const double eps = 1e-9; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; for(int i = 0; i < N; i++) cin >> A[i]; for(int i = 0; i < (1<<N); i++){ dp.push_back(OffsetVec<double>(200)); } for(int i = -200; i < 0; i++){ dp[(1<<N)-1][i] = 0.0; } for(int i = 1; i <= 200; i++){ dp[(1<<N)-1][i] = 1.0; } // kiriで終わる if(N%2 == 0) dp[(1<<N)-1][0] = 0.0; // nullで終わる if(N%2 == 1) dp[(1<<N)-1][0] = 1.0; for(int i = (1<<N)-2; i >= 0; i--){ vector<int> rem, used; for(int j = 0; j < N; j++){ if(i&(1<<j)) used.push_back(j); else rem.push_back(j); } for(int j = -200; j <= 200; j++){ double tmp = 0.0; for(int k : rem){ if(j+A[k] > 200) continue; double q = dp[i+(1<<k)][-j-A[k]]; double p = 1/A[k]; double cur = (1-p*q)/(2.0-p); tmp = max(tmp, cur); } dp[i][j] = tmp; } } cout << dp[0][0] << endl; }