結果
| 問題 |
No.298 話の伝達
|
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2015-11-16 18:32:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 405 ms / 5,000 ms |
| コード長 | 1,966 bytes |
| コンパイル時間 | 927 ms |
| コンパイル使用メモリ | 102,708 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 15:26:13 |
| 合計ジャッジ時間 | 3,704 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)
using ll = long long;
int const inf = 1<<29;
int N, M;
double G[22][22];
int main() {
minus(G);
cin >> N >> M;
rep(i, M) {
int a, b; double c; cin >> a >> b >> c; c /= 100;
G[a][b] = c;
}
double ans = 0.0; // N-1がyukicoderについて話す確率
rep(S, 1<<N) {
bitset<21> use(S);
if(!use[0] || !use[N-1]) { continue; } // 起点と終点は必ず話す
double PForS = 1.0; // 話すグループが集合Sであるときの確率(初期条件はグループ0が話す確率と考える)
REP(y, 1, N) { // グループ0は絶対話す
double PForYNotTaking = 1.0; // グループyの話さない確率
rep(x, N) {
if(use[x] && G[x][y] >= 0) {
PForYNotTaking *= 1.0 - G[x][y]; // xは話していたが、yに伝わらなかった
}
}
// printf("%.10f\n", PForYNotTaking);
// PForS[S] = Π_{y in S} PForXTaking[x]
if(!use[y]) {
PForS *= PForYNotTaking;
}
else {
PForS *= 1.0 - PForYNotTaking; // PForXTaking[y] = 1.0 - PForXNotTaking[y]
}
// printf("%.10f\n", PForS);
}
ans += PForS;
// puts("");
}
printf("%.15f\n", ans);
return 0;
}
moti