結果

問題 No.298 話の伝達
ユーザー pekempeypekempey
提出日時 2015-11-07 00:22:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,070 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 146,872 KB
実行使用メモリ 167,572 KB
最終ジャッジ日時 2023-10-11 14:43:22
合計ジャッジ時間 3,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 79 ms
167,572 KB
testcase_02 AC 79 ms
167,296 KB
testcase_03 AC 77 ms
167,348 KB
testcase_04 WA -
testcase_05 AC 49 ms
167,420 KB
testcase_06 WA -
testcase_07 AC 47 ms
167,352 KB
testcase_08 AC 48 ms
167,296 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 47 ms
167,380 KB
testcase_12 AC 47 ms
167,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 47 ms
167,300 KB
testcase_16 AC 57 ms
167,332 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

struct edge { int v; double c; };
int N, M;
vector<edge> g[20];
double dp[1 << 20][20];

double f(int s, int k) {
	if (k == 0) return 1.0;
	if (dp[s][k] >= 0) return dp[s][k];
	double p = 1;
	for (auto e : g[k]) if (~s & 1 << e.v) {
		p *= 1.0 - f(s | 1 << e.v, e.v) * e.c;
	}
	return dp[s][k] = 1.0 - p;
}

int main() {
	cin >> N >> M;
	rep (i, M) {
		int A, B, C;
		cin >> A >> B >> C;
		g[B].push_back({A, C / 100.0});
	}
	rep (i, 1 << 20) rep (j, 20) dp[i][j] = -1;
	double ans = f(1 << N - 1, N - 1);
	printf("%.20f\n", ans);
	return 0;
}
0