結果

問題 No.298 話の伝達
ユーザー motimoti
提出日時 2015-11-16 18:37:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 411 ms / 5,000 ms
コード長 2,016 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 99,972 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 16:48:57
合計ジャッジ時間 3,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,356 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 245 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 9 ms
4,352 KB
testcase_11 AC 391 ms
4,348 KB
testcase_12 AC 187 ms
4,348 KB
testcase_13 AC 411 ms
4,356 KB
testcase_14 AC 200 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 369 ms
4,348 KB
testcase_17 AC 5 ms
4,352 KB
testcase_18 AC 79 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 172 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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] = Π_{y1 in S, y2 in S\U} PForYTaking[y1] * PForYNotTalking[y2]
      if(!use[y]) {
        PForS *= PForYNotTaking;
      }
      else {
        PForS *= 1.0 - PForYNotTaking;      // PForYTaking[y] = 1.0 - PForYNotTaking[y]
      }
//      printf("%.10f\n", PForS);
    }
    ans += PForS;
//    puts("");
  }

  printf("%.15f\n", ans);

  return 0;
}
0