結果

問題 No.298 話の伝達
ユーザー mayoko_mayoko_
提出日時 2015-11-07 10:55:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 1,613 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 14:57:25
合計ジャッジ時間 2,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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>
#include<stack>

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;

struct Edge {
    int from;
    double p;
    Edge(){}
    Edge(int f, double p) : from(f), p(p) {}
};
const int MAXM = 300;
int A[MAXM], B[MAXM], C[MAXM];
vector<Edge> es[22];
bool is[22];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        es[B[i]].emplace_back(A[i], C[i]/100.);
    }
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    double ans = 0;
    for (int s = 0; s < 1<<(N-2); s++) {
        memset(is, false, sizeof(is));
        is[0] = is[N-1] = true;
        for (int i = 1; i < N-1; i++) if ((s>>(i-1))&1) is[i] = true;
        vector<double> p(N, 1);
        p[0] = 0;
        for (int i = 0; i < N; i++) {
            for (Edge e : es[i]) if (is[e.from]) {
                p[i] *= 1-e.p;
            }
        }
        double prob = 1;
        for (int i = 0; i < N; i++) {
            if (is[i]) prob *= 1-p[i];
            else prob *= p[i];
        }
        ans += prob;
    }
    printf("%.15lf\n", ans);
    return 0;
}
0