結果

問題 No.162 8020運動
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-18 00:36:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 656 ms / 5,000 ms
コード長 1,490 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 172,124 KB
実行使用メモリ 82,944 KB
最終ジャッジ日時 2024-11-15 18:58:25
合計ジャッジ時間 19,272 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int U = 14;
double dp[30][1<<15];

double calc(int& s, int& t, double& x, double& y, double& z) {
    double res = 1.0;
    for (int i=0; i<U; ++i){
        if ((s>>i)&1) {
            int cnt = 0;
            if (i && (s>>(i-1)&1)) cnt++;
            if (i+1<U && (s>>(i+1)&1)) cnt++;
            if (cnt==0) {
                if ((t>>i)&1) res *= 1.0-x;
                else res *= x;
            }
            else if (cnt == 1) {
                if ((t>>i)&1) res *= 1.0-y;
                else res *= y;
            }
            else {
                if ((t>>i)&1) res *= 1.0-z;
                else res *= z;
            }
        }
    }
    return res;
}


int main() {
    int n; cin >> n;
    n = 80 - n;
    double x, y, z; cin >> x >> y >> z;
    x /= 100.0;
    y /= 100.0;
    z /= 100.0;
    vector<vector<pair<int,double>>> p(1<<U);
    for (int s=0; s < (1<<U); s++) {
        int t = s;
        while (true) {
            p[s].push_back(make_pair(t, calc(s,t,x,y,z)));
            t = (t-1)&s;
            if (s == t) break;
        }
    }
    dp[0][(1<<U)-1] = 1.0;
    for (int i=0; i<n; ++i) {
        for (int s=0; s<(1<<U);++s){
            for (auto x: p[s]) {
                dp[i+1][x.first] += dp[i][s] * x.second;
            }
        }
    }
    double ans = 0.0;
    for (int s=0; s<(1<<U); ++s){
        ans += __builtin_popcount(s) * dp[n][s];
    }
    printf("%.12f\n", 2*ans);
}
0