結果

問題 No.298 話の伝達
ユーザー Grenache
提出日時 2015-11-09 10:55:04
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,250 ms / 5,000 ms
コード長 1,756 bytes
コンパイル時間 3,502 ms
コンパイル使用メモリ 77,940 KB
実行使用メモリ 57,948 KB
最終ジャッジ日時 2024-09-13 14:14:23
合計ジャッジ時間 10,331 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main_yukicoder298_1 {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        List<List<Edge>> edges = new ArrayList<List<Edge>>();
        for (int i = 0; i < n; i++) {
        	edges.add(new ArrayList<Edge>());
        }
        
        for (int i = 0; i < m; i++) {
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	int c = sc.nextInt();
        	
        	edges.get(b).add(new Edge(a, b, c));
        }

        int bit = 0, mask = 0;
        bit |= 0x1 << 0;
        mask |= 0x1 << 0;
        bit |= 0x1 << n - 1;
        mask |= 0x1 << n - 1;

        double ret = 0;
        for (int i = 0; i < 0x1 << n; i++) {
        	if ((i & mask) != bit) {
        		continue;
        	}

        	boolean[] yuki = new boolean[n];
        	for (int j = 0; j < n; j++) {
        		if ((i & 0x1 << j) != 0) {
        			yuki[j] = true;
        		}
        	}

        	double tmp = 1.0;
        	for (int j = 1; j < n; j++) {
        		double tmp2 = 1.0;
        		for (Edge from : edges.get(j)) {
        			if (yuki[from.a]) {
        				tmp2 *= (double)(100 - from.c) / 100;
        			}
        		}
        		
        		if (yuki[j]) {
        			tmp *= 1.0 - tmp2;
        		} else {
        			tmp *= tmp2;
        		}
        	}
        	
        	ret += tmp;
        }
        
        System.out.printf("%.7f\n", ret);
        
        sc.close();
    }
    
    private static class Edge {
    	int a;
//    	int b;
    	int c;
    	
    	Edge(int a, int b, int c) {
    		this.a = a;
//    		this.b = b;
    		this.c = c;
    	}
    }
}
0