fn solve(n: usize, m: usize, abp: &Vec<(u32, u32, u32)>) -> f64 { let full_bit = (1usize << n) - 1; let abpp = abp .iter() .map(|&(a, b, p)| { ( 1f64 / (a as f64), 1f64 / (b as f64), 1f64 / (p as f64), 1f64 - 1f64 / (p as f64), ) }) .collect::>(); let mut dp = [-f64::INFINITY; 4096]; for _ in 0..=m { let mut dpc = dp; dpc[0] = 0f64; for i in 1..=n { let mut bidx = (1 << i) - 1; while bidx <= full_bit { let mut point = 0f64; let mut pit = bidx; while pit > 0 { let pidx = pit.trailing_zeros() as usize; let pbit = pit & pit.wrapping_neg(); let dpidx = bidx ^ pbit; let (af, bf, psucc, pfail) = abpp[pidx]; point .chmax((dpc[dpidx] + af).max((dpc[dpidx] + bf) * psucc + dp[bidx] * pfail)); pit &= pit.wrapping_sub(1); } dpc[bidx].chmax(point); bidx = bidx.next_combination(); } } dp = dpc; } dp[full_bit] } fn main() { let mut stdinlock = std::io::stdin().lock(); let mut lines = std::io::BufRead::lines(&mut stdinlock).map_while(Result::ok); let (n, m) = { let s = lines.next().unwrap(); let mut t = s.split_ascii_whitespace(); ( t.next().unwrap().parse::().unwrap(), t.next().unwrap().parse::().unwrap(), ) }; let abp = (0..n) .map(|_| { let s = lines.next().unwrap(); let mut t = s.split_ascii_whitespace(); ( t.next().unwrap().parse::().unwrap(), t.next().unwrap().parse::().unwrap(), t.next().unwrap().parse::().unwrap(), ) }) .collect::>(); println!("{}", solve(n, m, &abp)); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } trait NextCombBits { fn next_combination(self) -> Self; } impl NextCombBits for usize { fn next_combination(self) -> Self { let t = self.wrapping_add(self & self.wrapping_neg()); (((self & !t) >> self.trailing_zeros()) >> 1) | t } }