結果

問題 No.298 話の伝達
ユーザー yukiyuki
提出日時 2015-11-14 05:12:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 453 ms / 5,000 ms
コード長 1,042 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 145,044 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 17:40:31
合計ジャッジ時間 4,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

int N,M;
double rr[21][21];
int yes[21];

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> M;

  REP(i,M){
    int a,b,c;
    cin >> a >> b >> c;
    rr[a][b] = c / 100.0;
  }

  double ans = 0.0;

  for(int mask=0; mask<1<<N; mask++){
    REP(i,N){ yes[i] = (mask >> i) & 1; }
    if(yes[0] == 0 || yes[N-1] == 0) continue;

    double p = 1.0;
    FOR(i,1,N){
      double p_i = 1.0;
      REP(j,N){ if(yes[j] && rr[j][i]) p_i*=(1.0 - rr[j][i]); }
      if(yes[i]) p*=1.0-p_i;
      else p*=p_i;
    }
    ans += p;
  }

  cout << setprecision(12) << fixed;
  cout << ans << endl;

  return 0;
}
0