結果

問題 No.574 正多面体サイコロ
ユーザー hatoo
提出日時 2017-10-11 20:44:34
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 3,070 bytes
コンパイル時間 12,394 ms
コンパイル使用メモリ 382,120 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 09:45:04
合計ジャッジ時間 14,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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