Problem:
Score: 400 points

Problem Statement

Amidakuji is a traditional method of lottery in Japan.

To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.

A valid amidakuji is an amidakuji that satisfies the following conditions:

No two horizontal lines share an endpoint.

The two endpoints of each horizontal lines must be at the same height.

A horizontal line must connect adjacent vertical lines.

Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.

For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.

Constraints

H is an integer between 1 and 100 (inclusive).

W is an integer between 1 and 8 (inclusive).

K is an integer between 1 and W (inclusive).

Input

Input is given from Standard Input in the following format:

H W K

Output

Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

1 3 2

Sample Output 1

1

Only the following one amidakuji satisfies the condition:

Sample Input 2

1 3 1

Sample Output 2

2

Only the following two amidakuji satisfy the condition:

Sample Input 3

2 3 3

Sample Output 3

1

Only the following one amidakuji satisfies the condition:

Sample Input 4

2 3 1

Sample Output 4

5

Only the following five amidakuji satisfy the condition:

Sample Input 5

7 1 1

Sample Output 5

1

As there is only one vertical line, we cannot draw any horizontal lines. Thus, there is only one amidakuji that satisfies the condition: the amidakuji with no horizontal lines.

Sample Input 6

15 8 5

Sample Output 6

437760187

Be sure to print the answer modulo 1\ 000\ 000\ 007.

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! fn_memo{
    ($fun:ident : $memo:ident ( $($param:ident : usize),* ; $($ex_param:ident : $ep_ty:ty),* ) -> $out:ty $body:block) => {
        fn $fun($memo:&mut memo_inner!(type $out; $($param),*), $($param : usize),* , $($ex_param : $ep_ty),*) -> $out $body
    };
}
macro_rules! memo{
    ( $memo:ident ( $($inf_arg:expr),* ) -> $out:ty) => {
        let mut $memo = &mut memo_inner!(vec $out; $($inf_arg),*);
    };
}
macro_rules! memo_inner {
    (type $out:ty ; $param:ident) => {
        Vec<Option<$out>>
    };
    (type $out:ty ; $param:ident, $($p:ident),*) => {
        Vec<memo_inner!(type $out; $($p),*)>
    };
    (vec $out:ty; $inf_arg:expr) => {
        vec![None as Option<$out>; $inf_arg]
    };
    (vec $out:ty; $inf_arg:expr, $($ia:expr),*) => {
        vec![memo_inner!(vec $out; $($ia),*); $inf_arg]
    };
}
macro_rules! get{
    ($fun:ident : $memo:ident ( $($arg:expr),* ;  $($ex_arg:expr),* )) => {{
        if $memo$([$arg])*.is_none() {
            $memo$([$arg])* = Some($fun($memo, $($arg),* , $($ex_arg),*));
        }
        $memo$([$arg])*.unwrap()
    }};
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let h: usize = sc.read();
    let w: usize = sc.read();
    let k: usize = sc.read();
    let ptn = vec![1, 1, 2, 3, 5, 8, 13, 21, 34];
    let ptn = ptn.iter().map(|&n| Finite(n)).collect();
    // ptn[w] = 幅 w-1 , 高さ 1 のあみだの総数
    memo!{ cm(101, 9) -> Finite };
    format!("{}\n", get!{ clc:cm(h, k; w, &ptn) })
}
fn_memo! { clc:cm(r:usize, c:usize; w:usize, ptn:&Vec<Finite>) -> Finite {
    if r == 0 {
        if c == 1 {
            return Finite(1)
        } else {
            return Finite(0)
        }
    }
    let mut ret = ptn[c-1] * ptn[w-c] * get!{ clc:cm(r-1, c; w, ptn) };
    if c > 1 {
        ret += ptn[c-2] * ptn[w-c] * get!{ clc:cm(r-1, c-1; w, ptn)};
    }
    if c < w {
        ret += ptn[c-1] * ptn[w-c-1] * get!{ clc:cm(r-1, c+1; w, ptn)};
    }
    ret
}}
#[test]
fn test_solve() {
   assert_eq!(solve("1 3 2\n"), "1\n");
   assert_eq!(solve("1 3 1\n"), "2\n");
   assert_eq!(solve("2 3 3\n"), "1\n");
   assert_eq!(solve("2 3 1\n"), "5\n");
   assert_eq!(solve("7 1 1\n"), "1\n");
   assert_eq!(solve("15 8 5\n"), "437760187\n");
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Finite(u64);
const MOD: u64 = 1_000_000_007;
impl Finite {
    pub fn pow(self, mut exp: u32) -> Self {
        let mut base = self.0;
        let mut acc = 1;
        while exp > 1 {
            if (exp & 1) == 1 {
                acc = acc * base % MOD;
            }
            exp /= 2;
            base = base * base % MOD;
        }
        if exp == 1 {
            acc = acc * base % MOD;
        }
        Finite(acc)
    }
}
impl std::fmt::Display for Finite {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl std::ops::Neg for Finite {
    type Output = Self;
    fn neg(self) -> Self {
        Finite(0) - self
    }
}
impl std::ops::Add for Finite {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        Finite((self.0 + rhs.0) % MOD)
    }
}
impl std::ops::AddAssign for Finite {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}
impl std::ops::Sub for Finite {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        Finite((self.0 + MOD - rhs.0) % MOD)
    }
}
impl std::ops::SubAssign for Finite {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}
impl std::ops::Mul for Finite {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        Finite(self.0 * rhs.0 % MOD)
    }
}
impl std::ops::MulAssign for Finite {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}
impl std::ops::Div for Finite {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        self * rhs.pow((MOD - 2) as u32)
    }
}
impl std::ops::DivAssign for Finite {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}
impl std::iter::Sum<Finite> for Finite {
    fn sum<I: Iterator<Item = Finite>>(iter: I) -> Finite {
        iter.fold(Finite(0), |a, b| a + b)
    }
}
impl<'a> std::iter::Sum<&'a Finite> for Finite {
    fn sum<I: Iterator<Item = &'a Finite>>(iter: I) -> Finite {
        iter.fold(Finite(0), |a, b| a + *b)
    }
}
impl std::iter::Product<Finite> for Finite {
    fn product<I: Iterator<Item = Finite>>(iter: I) -> Finite {
        iter.fold(Finite(1), |a, b| a * b)
    }
}
impl<'a> std::iter::Product<&'a Finite> for Finite {
    fn product<I: Iterator<Item = &'a Finite>>(iter: I) -> Finite {
        iter.fold(Finite(1), |a, b| a * *b)
    }
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
#[allow(dead_code)]
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}