結果

問題 No.298 話の伝達
ユーザー mayoko_mayoko_
提出日時 2015-07-26 23:44:02
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,678 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 81,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 23:46:00
合計ジャッジ時間 2,005 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 18 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 67 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

const int MAXN = 25;
double dp[MAXN];

struct edge {
    int to;
    double trans;
    edge() {}
    edge(int to, double trans) : to(to), trans(trans) {}
};

vector<edge> rG[MAXN];

double dfs(int now) {
    if (now == 0) return 0;
    double& ret = dp[now];
    if (ret >= 0) return ret;
    ret = 0;
    int n = rG[now].size();
    vector<double> P(n);
    for (int i = 0; i < (int)rG[now].size(); i++) {
        P[i] = dfs(rG[now][i].to);
    }
    for (int s = 0; s < (1<<n); s++) {
        double tmp = 1;
        for (int i = 0; i < n; i++) {
            if ((s>>i)&1) {
                tmp *= P[i];
            } else {
                tmp *= (1-P[i]) * (1-rG[now][i].trans);
            }
        }
        ret += tmp;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        double p = c/100.;
        rG[b].emplace_back(a, p);
    }
    for (int i = 0; i < MAXN; i++) dp[i] = -1;
    printf("%.15lf\n", 1-dfs(n-1));
    return 0;
}
0