use fio::*; const N: usize = 14; fn main() { let a = read::(); let [p0, p1, p2] = read_tuple::(); let (p0, p1, p2) = (p0 as f64 / 100.0, p1 as f64 / 100.0, p2 as f64 / 100.0); // exp value of remaining teeth for consecutive i teeth let mut dp = (0..=N).into_iter().map(|x| x as f64).collect::>(); for _ in 0..80 - a { let mut ndp = vec![0.0; N + 1]; ndp[1] = dp[1] * (1.0 - p0); for ln in 2..=N { let mut ans = 0.0; let mut prob = vec![1.0]; for j in 0..ln { prob.push(0.0); let p = if j == 0 || j == ln - 1 { p1 } else { p2 }; let mut p0 = 0.0; for k in (0..=j).rev() { ans += p * dp[k] * prob[k]; prob[k + 1] = (1.0 - p) * prob[k]; p0 += p * prob[k]; } prob[0] = p0; } for j in 0..=ln { ans += dp[j] * prob[j]; } ndp[ln] = ans; } dp = ndp; } println!("{:.9}", 2.0 * dp[N]); } mod fio { use std::{ cell::RefCell, convert::TryInto, fmt::Debug, io::{BufRead, BufWriter, StdinLock, StdoutLock, stdin, stdout}, str::FromStr, }; thread_local! { pub static STDIN: RefCell> = RefCell::new(stdin().lock()); pub static STDOUT: RefCell>> = RefCell::new(BufWriter::new(stdout().lock())); } #[allow(dead_code)] pub fn read() -> T where ::Err: Debug, { read_line().parse().unwrap() } #[allow(dead_code)] pub fn read_vec() -> Vec where ::Err: Debug, { read_line() .split_whitespace() .map(|x| x.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn read_tuple() -> [T; N] where T: FromStr + Debug, ::Err: Debug, { read_vec::().try_into().unwrap() } /// whitespace at the end of the line is ignored pub fn read_line() -> String { let mut s = String::new(); STDIN.with(|cell| { cell.borrow_mut().read_line(&mut s).unwrap(); }); String::from_str(s.trim_end()).unwrap() } } #[macro_export] macro_rules! print { ($($t:tt)*) => { fio::STDOUT.with(|cell|{ use std::io::Write; write!(cell.borrow_mut(), $($t)*).unwrap() })}; } #[macro_export] macro_rules! println { ($($t:tt)*) => { fio::STDOUT.with(|cell| { use std::io::Write; writeln!(cell.borrow_mut(), $($t)*).unwrap() }) }; } #[macro_export] macro_rules! flush { () => { fio::STDOUT.with(|cell| { use std::io::Write; cell.borrow_mut().flush().unwrap() }); }; }