use fio::*; /// dp[t][c]: prob of card c popping in turn t fn calc(n: usize, p: f64) -> Vec> { let mut dp = vec![vec![0f64; n]; n]; // prob[c][i]: prob of c'th card existing in i'th position let mut prob = vec![vec![0f64; n]; n]; for i in 0..n { prob[i][i] = 1.0; } for rem in (1..=n).rev() { if rem == 1 { for c in 0..n { dp[n - rem][c] = prob[c][0]; } } else { let mut nprob = vec![vec![0f64; rem - 1]; n]; let q = (1.0 - p) / (rem - 1) as f64; // i -> dp: if i == 0 { p } else { q } // i -> i-1: p + (i-1) * q (ignore on i=0) // i -> i: (rem-1-i) * q (ignore on i=rem-1) for c in 0..n { for i in 0..rem { dp[n - rem][c] += prob[c][i] * if i == 0 { p } else { q }; if i != 0 { nprob[c][i - 1] += prob[c][i] * (p + (i - 1) as f64 * q); } if i != rem - 1 { nprob[c][i] += prob[c][i]*((rem - 1 - i) as f64 * q); } } } prob = nprob; } } dp } fn main() { let [n, pa, pb] = read_tuple::(); let n: usize = n.parse().unwrap(); let (pa, pb): (f64, f64) = (pa.parse().unwrap(), pb.parse().unwrap()); let mut a = read_vec::(); let mut b = read_vec::(); a.sort_by(|a, b| a.total_cmp(b)); b.sort_by(|a, b| a.total_cmp(b)); let pa = calc(n, pa); let pb = calc(n, pb); let mut ans = 0.0; for t in 0..n { for i in 0..n { for j in 0..n { if a[i] > b[j] { ans += pa[t][i] * pb[t][j] * (a[i] + b[j]); } } } } println!("{:.12}", ans); } 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() }); }; }