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! memo{
    ($memo:ident ( $($max_arg:expr),* ) -> $out:ty) => {
        let mut $memo = &mut memo!(inner $out; $($max_arg),*);
    };
    (inner $out:ty; $max_arg:expr) => {
        vec![None as Option<$out>; $max_arg + 1]
    };
    (inner $out:ty; $max_arg:expr, $($ma:expr),*) => {
        vec![memo!(inner $out; $($ma),*); $max_arg + 1]
    };
}
macro_rules! fn_memo{
    ($fun:ident ( $memo:ident; $($param:ident),* ; $($ex_param:ident : $ty:ty),* ) -> $out:ty $body:block) => {
        fn $fun($memo:&mut fn_memo!(inner $out; $($param),*), $($param : usize),* , $($ex_param : $ty),*) -> $out{
            if $memo$([$param])*.is_none() {
                $memo$([$param])* = Some($body);
            }
            $memo$([$param])*.unwrap()
        }
    };
    (inner $out:ty ; $param:ident) => {
        Vec<Option<$out>>
    };
    (inner $out:ty ; $param:ident, $($p:ident),*) => {
        Vec<fn_memo!(inner $out; $($p),*)>
    };
}

////////////////////////////////////////////////////////////////////////

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(100, 8) -> Finite };
    format!("{}\n", clc(cm, h, k, w, &ptn))
}
fn_memo! { clc(cm; r, c ; 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] * clc(cm, r-1, c, w, ptn) ;
    if c > 1 {
        ret += ptn[c-2] * ptn[w-c] * clc(cm, r-1, c-1, w, ptn);
    }
    if c < w {
        ret += ptn[c-1] * ptn[w-c-1] * 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");
}
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();
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Finite(u64);
const MOD: u64 = 1_000_000_007;
impl std::fmt::Display for Finite {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
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::Mul for Finite {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        Finite(self.0 * rhs.0 % MOD)
    }
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
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")
    }
}