結果

問題 No.574 正多面体サイコロ
ユーザー hatoohatoo
提出日時 2017-10-11 20:44:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 3,070 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 143,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 23:08:31
合計ジャッジ時間 3,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 15 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 60 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 79 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}


#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let (f, n, k): (usize, usize, usize) = util::get3();
    let mut e = 0.0;

    for m in 1..f + 1 {
        let mut dp = vec![vec![vec![0.0; k + 1]; k]; n + 1];

        dp[0][0][0] = 1.0;
        for i in 1..n + 1 {
            for j in 0..k {
                for h in 0..k + 1 {
                    if h >= 1 {
                        dp[i][j][h] += dp[i - 1][j][h - 1] / f as f64;
                    }
                    if h == k {
                        dp[i][j][h] += dp[i - 1][j][h] / f as f64;
                    }
                    if j >= 1 {
                        dp[i][j][h] += dp[i - 1][j - 1][h] * ((f - m) as f64) / f as f64;
                    }
                    dp[i][j][h] += dp[i - 1][j][h] * ((m - 1) as f64) / f as f64;
                }
            }
        }

        for i in 0..k {
            for j in 0..k + 1 {
                if j >= k - i {
                    e += m as f64 * dp[n][i][j];
                }
            }
        }
    }

    println!("{}", e);
}
0