https://atcoder.jp/contests/abc289/tasks/abc289_d
ただのDPですね。
// Step Up Robot #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn YesNo(b: bool) -> String { return if b { "Yes".to_string() } else { "No".to_string() } } //////////////////// process //////////////////// fn read_input() -> (Vec<usize>, Vec<usize>, usize) { let _N: usize = read(); let A = read_vec(); let _M: usize = read(); let B = read_vec(); let X = read(); (A, B, X) } fn f(A: Vec<usize>, B: Vec<usize>, X: usize) -> bool { let mut dp: Vec<bool> = (0..X+1).map(|_| false).collect(); dp[0] = true; let mut bs: Vec<bool> = (0..X+1).map(|_| true).collect(); for b in B.into_iter() { bs[b] = false } for i in 1..X+1 { dp[i] = bs[i] && A.iter().any(|a| i - a < i && dp[i-a]) } dp[X] } fn main() { let (A, B, X) = read_input(); println!("{}", YesNo(f(A, B, X))) }