結果
問題 |
No.298 話の伝達
|
ユーザー |
![]() |
提出日時 | 2015-11-07 10:55:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 263 ms / 5,000 ms |
コード長 | 1,613 bytes |
コンパイル時間 | 717 ms |
コンパイル使用メモリ | 90,216 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 13:49:37 |
合計ジャッジ時間 | 2,239 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#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; }