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 (Python):
h,w,k = map(int,input().split())
mod = 10**9+7

if w == 1:
    print(1)
    exit()

dp = [[0]*w for i in range(h+1)]
dp[0][0] = 1

l = [[0]*3 for i in range(w)]

for i in range(2**(w-1)):
    if "11" in bin(i):
        continue

    for j in range(w-1):
        if (i >> j) & 1:        
            l[j][2] += 1
            l[j+1][0] += 1

fib = [1,1]
for i in range(10):
    fib.append(fib[-1]+fib[-2])
for i in l:
    i[1] = fib[w] - sum(i)

for i in range(h):
    for j in range(w):
        dp[i+1][j] += dp[i][j]*l[j][1]%mod
        if j != 0:
            dp[i+1][j] += dp[i][j-1]*l[j][0]%mod
        if j != w-1:
            dp[i+1][j] += dp[i][j+1]*l[j][2]%mod
        dp[i+1][j] %= mod

print(dp[-1][k-1]%mod)

Solution (Python):
h,w,K=map(int,input().split())
mod=10**9+7
dp=[[0 for i in range(w)] for j in range(h+1)]
for i in range(2**(w-1)):dp[0][0]=1
for i in range(1,h+1):
    for j in range(2**(w-1)):
        s=format(j,"b").zfill(w-1)
        if "11" in s:continue
        exchanged=[False]*w
        for k in range(w-1):
            if s[k]=="1":
                dp[i][k]+=dp[i-1][k+1]
                dp[i][k+1]+=dp[i-1][k]
                dp[i][k]%=mod
                dp[i][k+1]%=mod
                exchanged[k]=True
                exchanged[k+1]=True
        for k in range(w):
            if exchanged[k]:continue
            dp[i][k]+=dp[i-1][k]
            dp[i][k]%=mod

print(dp[-1][K-1])

Solution (Python):
def main():
    MOD = 10 ** 9 + 7

    H, W, K = map(int, input().split())

    dp = [[0] * W for _ in range(H + 1)]
    dp[0][0] = 1
    
    

    for h in range(H):
        for bit in range(1 << (W - 1)):
            if '11' in bin(bit): continue
            toes = list(range(W))
            for j in range(W - 1):
                if (bit >> j) & 1:
                    toes[j], toes[j + 1] = toes[j + 1], toes[j]
            for frm, to in enumerate(toes):
                dp[h + 1][to] = (dp[h + 1][to] + dp[h][frm]) % MOD
    ans = dp[H][K - 1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
h, w, k = map(int, input().split())
p = 10**9+7
DP = [[0 for j in range(w+1)] for i in range(h+1)]
DP[0][0] = 1
F = [1, 2, 3, 5, 8, 13, 21][:w]+[1]
for i in range(h):
    for j in range(w):
        a = DP[i][j-1]*F[j-2]*F[w-2-j]
        b = DP[i][j]*F[j-1]*F[w-2-j]
        c = DP[i][j+1]*F[j-1]*F[w-3-j]
        DP[i+1][j] = (a+b+c) % p
print(DP[h][k-1])

Solution (Python):
MOD = 10**9 + 7
H, W, K = map(int,input().split())
dp = [[0 for k in range(W)] for l in range(H+1)]
dp[0][0] = 1
A = []  
for b in range(2**(W-1)):
    if "11" not in bin(b):
        A.append(bin(b)[2:].zfill(W-1))

for k in range(H):
    for e in A:
        for i in range(W):
            if i < W-1 and e[i] == "1": 
                dp[k+1][i+1] += dp[k][i]
                dp[k+1][i+1] %= MOD
            elif i >= 1 and e[i-1] == "1": 
                dp[k+1][i-1] += dp[k][i]
                dp[k+1][i-1] %= MOD
            else:
                dp[k+1][i] += dp[k][i]
                dp[k+1][i] %= MOD

print(dp[H][K-1])

Solution (Python):
h,w,k = map(int,input().split())

move = [[0 for i in range(w)] for j in range(w)]
from itertools import product
for bits in product([0, 1], repeat=w-1):
    flag = True
    for i in range(w-2):
        if bits[i] == 1 and bits[i+1] == 1:
            flag = False
    if not flag:
        continue

    for i in range(w):
        a = 0
        if i != 0:
            if bits[i-1] == 1:
                move[i][i-1] += 1
                a = 1
        if i != w-1:
            if bits[i] == 1:
                move[i][i+1] += 1
                a = 1
        if a == 0:
            move[i][i] += 1

dp = [[0 for i in range(w)] for j in range(h+1)]

dp[0][0] = 1
MOD = 10**9 + 7

for i in range(h):
    for j in range(w):
        for k1 in range(w):
            dp[i+1][k1] += dp[i][j] * move[j][k1]
            dp[i+1][k1] %= MOD


print(dp[-1][k-1])

Solution (Python):
h, w, k = map(int, input().split())
p = 10**9+7

DP = [[0 for j in range(w+1)] for i in range(h+1)]
DP[0][0] = 1

F = [1, 1, 2, 3, 5, 8, 13, 21]
for i in range(h):
    for j in range(w):
        a = DP[i][j-1]*F[j-1]*F[w-1-j]
        b = DP[i][j]*F[j]*F[w-1-j]
        c = DP[i][j+1]*F[j]*F[w-2-j]
        DP[i+1][j] = (a+b+c) % p
print(DP[h][k-1])

Solution (Python):
h, w, k = map(int, input().split())




p = 10**9+7


DP = [[0 for j in range(w+1)] for i in range(h+1)]
DP[0][0] = 1
F = [1, 1, 2, 3, 5, 8, 13, 21]
for i in range(h):
    for j in range(w):
        a = DP[i][j-1]*F[j-1]*F[w-1-j]
        b = DP[i][j+1]*F[j]*F[w-2-j]
        c = DP[i][j]*F[j]*F[w-1-j]
        DP[i+1][j] = (a+b+c) % p
print(DP[h][k-1])

Solution (Python):
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7


def main():
    H, W, K = map(int, input().split())
    dp = [[0] * W for _ in range(H + 1)]  
    dp[0][0] = 1  
    for h in range(H):
        for bit in range(1 << (W - 1)):  
            if '11' in bin(bit): continue  
            for w in range(W):
                
                if w and bit & (1 << (w - 1)):  
                    dp[h + 1][w - 1] += dp[h][w] % MOD
                elif bit & (1 << w):  
                    dp[h + 1][w + 1] += dp[h][w] % MOD
                else:  
                    dp[h + 1][w] += dp[h][w] % MOD
    
    
    print(dp[H][K - 1] % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
H,W,K = map(int, input().split())

if W == 1:
    print(1 if K == 1 else 0)
    exit()

MOD = 10 ** 9 + 7

states = [0]
for state in range(1, 1 << (W - 1)):
    flag = True
    for j in range(1, W - 1):
        if ((state >> j - 1) & 1) and ((state >> j) & 1):
            flag = False
    if flag: states.append(state)

dp = [[0] * W for _ in range(H + 1)]

dp[0][0] = 1


for i in range(H):
    for state in states:
        for j in range(W - 1):
            if (state >> j) & 1:
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD
            else:
                if j == 0:
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD
                elif not ((state >> j - 1) & 1):
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD
                if j == W - 2:
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j + 1]) % MOD

print(dp[H][K - 1])

Solution (Python):
"""
    dp[h][w]: h番目のrow(h: 0~H(終着))で棒w(w: 0~W-1)にいる状態になるための横線(0~h)の組合せ数
    dp[h][w] = A*dp[h-1][w-1] + B*dp[h-1][w] + C*dp[h-1][w+1] O(100*8)
    A, B, Cはなんかうまいこと決めれそう。(全探索でもO(7*7*7))
    """
def main():
    import sys
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    dp = [[0]*W for _ in range(H+1)]
    dp[0][0] = 1
    for h in range(1, H+1):
        for w in range(W):
            A, B, C = 0, 0, 0
            for i in range(2 ** (W-1)):
                lines = []
                for j in range(W-1):
                    if ((i >> j) & 1):
                        if lines and lines[-1]:
                            break
                        lines.append(True)
                    else:
                        lines.append(False)
                else:
                    if w-1 >= 0 and lines[w-1]:
                        A += 1
                    elif w <= W-2 and lines[w]:
                        C += 1
                    else:
                        B += 1
            if w-1 >= 0:
                dp[h][w] += dp[h-1][w-1] * A
            dp[h][w] += dp[h-1][w] * B
            if w+1 <= W-1:
                dp[h][w] += dp[h-1][w+1] * C
    print(dp[H][K-1] % (10**9+7))
    

if __name__ == '__main__':
    main()

Solution (Python):
"""
    dp[h][w]: h番目のrow(h: 0~H(終着))で棒w(w: 0~W-1)にいる状態になるための横線(0~h)の組合せ数
    dp[h][w] = A*dp[h-1][w-1] + B*dp[h-1][w] + C*dp[h-1][w+1] O(100*8)
    A, B, Cはなんかうまいこと決めれそう。(全探索でもO(7*7*3))
    o(10**6)には入りそう
    """
def main():
    import sys
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    dp = [[0]*W for _ in range(H+1)]
    dp[0][0] = 1
    for h in range(1, H+1):
        for w in range(W):
            A, B, C = 0, 0, 0
            for i in range(2 ** (W-1)):
                lines = []
                for j in range(W-1):
                    if ((i >> j) & 1):
                        if lines and lines[-1]:
                            break
                        lines.append(True)
                    else:
                        lines.append(False)
                else:
                    if w-1 >= 0 and lines[w-1]:
                        A += 1
                    elif w <= W-2 and lines[w]:
                        C += 1
                    else:
                        B += 1
            if w-1 >= 0:
                dp[h][w] += dp[h-1][w-1] * A
            dp[h][w] += dp[h-1][w] * B
            if w+1 <= W-1:
                dp[h][w] += dp[h-1][w+1] * C
    print(dp[H][K-1] % (10**9+7))
    

if __name__ == '__main__':
    main()

Solution (Python):
"""
    dp[h][w]: h番目のrow(h: 0~H(終着))で棒w(w: 0~W-1)にいる状態になるための横線(0~h)の組合せ数
    dp[h][w] = A*dp[h-1][w-1] + B*dp[h-1][w] + C*dp[h-1][w+1] o(1000)
    A, B, Cはなんかうまいこと決めれそう。(全探索でもmax7*7*3通り)o(1000) 
    どうやってもO(10**6)には入りそう
    """
def main():
    import sys
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    dp = [[0]*W for _ in range(H+1)]
    dp[0][0] = 1
    for h in range(1, H+1):
        for w in range(W):
            A, B, C = 0, 0, 0
            for i in range(2 ** (W-1)):
                lines = []
                for j in range(W-1):
                    if ((i >> j) & 1):
                        if lines and lines[-1]:
                            break
                        lines.append(True)
                    else:
                        lines.append(False)
                else:
                    if w-1 >= 0 and lines[w-1]:
                        A += 1
                    elif w <= W-2 and lines[w]:
                        C += 1
                    else:
                        B += 1
            if w-1 >= 0:
                dp[h][w] += dp[h-1][w-1] * A
            dp[h][w] += dp[h-1][w] * B
            if w+1 <= W-1:
                dp[h][w] += dp[h-1][w+1] * C
    print(dp[H][K-1] % (10**9+7))
    

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w, k = map(int, readline().split())
dp = [[0] * w for _ in range(h + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(h):
    for b in range(1 << (w - 1)):
        if '11' in bin(b):
            continue
        for j in range(w):
            if j and b & (1 << (j - 1)):
                dp[i + 1][j - 1] += dp[i][j]
            elif b & (1 << j):
                dp[i + 1][j + 1] += dp[i][j]
            else:
                dp[i + 1][j] += dp[i][j]
print(dp[-1][k - 1] % mod)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  




H, W, K = read_ints()
if W == 1:
    print(1)
    exit()  





dp = [[0] * W for _ in ra(H + 1)]
dp[0][0] = 1



def check_valid(p):
    
    for pp, ppp in zip(p, p[1:]):
        if pp == 1 and ppp == 1:
            return False
    return True


def generate_ij_to_swap():
    ret = []
    for p in product(range(2), repeat=W - 1):
        if not check_valid(p):
            continue
        pre = False
        for i, pp in enu(p):
            if pp:
                ret.append((i, i + 1))
                ret.append((i + 1, i))
            elif pre == 0 and pp == 0:
                ret.append((i, i))  
            pre = pp
        if pre == 0:
            ret.append((i + 1, i + 1))
    return ret


swap_idx = generate_ij_to_swap()


for h in ra(H):
    for i, j in swap_idx:
        dp[h + 1][j] += dp[h][i] % MOD  

print(dp[H][K - 1] % MOD)

Solution (Python):
H,W,K = list(map(int,input().split()))
mod = 1000000007

f = [0]*(W+1)
f[0] = 1
f[1] = 2
for i in range(2,W+1):
    f[i] = f[i-1] + f[i-2]

dp = [[0]*(W+2) for _ in range(H+1)]
dp[0][K] = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        dp[i][j] += (dp[i-1][j] * f[max(0,j-2)] * f[max(0,W-j-1)]
                     + dp[i-1][j-1] * f[max(0,j-3)] * f[max(0,W-j-1)]
                     + dp[i-1][j+1] * f[max(0,j-2)] * f[max(0,W-j-2)] )
        dp[i][j] %= mod
print(dp[-1][1])

Solution (Python):
H,W,K = map(int,input().split())
dp = [[0]*W for i in range(H+1)]
dp[0][0] = 1
MOD = 10**9+7
for i in range(H):
    for b in range(1<<(W-1)):
        if '11' in bin(b): continue
        for k in range(W):
            if k and b&(1<<(k-1)):
                dp[i+1][k-1] += dp[i][k]
            elif b&(1<<k):
                dp[i+1][k+1] += dp[i][k]
            else:
                dp[i+1][k] += dp[i][k]
print(dp[-1][K-1] % MOD)

Solution (Python):
H,W,K=map(int, input().split())

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

def comb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

p = [1]*(8+1)
p[1] = 2
p[2] = 3
for i in range(3,W+1):
    p[i] = p[i-1] + p[i-2]

def f(x):
    if x < 1: return 1
    return p[x]

dp = [[Mint() for _ in range(W+2)] for __ in range(H+1)]
dp[0][K] += 1
for r in range(H):
    for c in range(1, W+1):
        if c >= 2:
            dp[r+1][c-1] += dp[r][c] * (f(c-3) * f(W-c-1))
        dp[r+1][c] += dp[r][c] * (f(c-2) * f(W-c-1))
        if c <= W-1:
            dp[r+1][c+1] += dp[r][c] * (f(c-2) * f(W-c-2))
print(dp[H][1])

Solution (Python):
H,W,K = map(int,input().split())
MOD = 10**9+7

dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for b in range(1<<(W-1)):
        if '11' in bin(b): continue
        for k in range(W):
            if k and b&(1<<(k-1)):
                dp[i+1][k-1] += dp[i][k]
            elif b&(1<<k):
                dp[i+1][k+1] += dp[i][k]
            else:
                dp[i+1][k] += dp[i][k]

print(dp[-1][K-1] % MOD)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w,k = LI()
    dp = [[0]*w for _ in range(h+1)]
    dp[0][0] = 1
    k -= 1
    f = [1,1]
    for i in range(w):
        f.append(f[-1]+f[-2])

    for i in range(h):
        ni = i+1
        for j in range(w):
            dpj = dp[i][j]
            nj = j+1
            if nj < w:
                l = f[j]
                r = f[w-1-nj]
                dp[ni][nj] += l*r*dpj%mod
            l = f[j]
            r = f[w-1-j]
            dp[ni][j] += l*r*dpj%mod
            nj = j-1
            if nj >= 0:
                l = f[nj]
                r = f[w-1-j]
                dp[ni][nj] += l*r*dpj%mod
    print(dp[h][k]%mod)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
import sys
mod = 7 + 10 ** 9

def solve():
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    DP = [[0] * W for _ in range(H + 1)]
    pattern = [1, 2, 3, 5, 8, 13, 21]
    DP[0][0] = 1
    for h in range(H):
        for w in range(W):
            if w == 0:
                DP[h+1][w] += (DP[h][w] * pattern[max(0, W - 2)]) % mod
                if W > 1: DP[h+1][w] += (DP[h][w+1] * pattern[max(0, W - 3)]) % mod
            elif w == W - 1:
                DP[h+1][w] += (DP[h][w] * pattern[max(0, W - 2)]) % mod
                if W > 1: DP[h+1][w] += (DP[h][w-1] * pattern[max(0, W - 3)]) % mod
            else:
                DP[h+1][w] += (DP[h][w]  * pattern[max(0, w - 1)] * pattern[max(0, W - w - 2)]) % mod
                DP[h+1][w] += (DP[h][w+1] * pattern[max(0, w - 1)] * pattern[max(0, W - w - 3)]) % mod
                DP[h+1][w] += (DP[h][w-1] * pattern[max(0, w - 2)] * pattern[max(0, W - w - 2)]) % mod
            DP[h+1][w] %= mod
    print(DP[H][K - 1])

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from functools import lru_cache

H, W, K = map(int, input().split())
MOD = 10**9 + 7
K -= 1

if W == 1:
    print(1)
    exit()

@lru_cache(maxsize=None)
def fib(width):
    if width < -1:
        return 0
    if width == -1:
        return 1
    return (fib(width - 1) + fib(width - 2)) % MOD

dp = [0] * W
dp[0] = 1

for _ in range(H):
    newDp = [0] * W

    newDp[0] = (dp[0] * fib(W - 2) + dp[1] * fib(W - 3)) % MOD
    newDp[W - 1] = (dp[W - 1] * fib(W - 2) + dp[W - 2] * fib(W - 3)) % MOD

    for w in range(1, W - 1):
        left = dp[w - 1] * max(1, fib(w - 2)) * max(1, fib(W - 1 - w - 1))
        right = dp[w + 1] * max(1, fib(w - 1)) * max(1, fib(W - 1 - w - 2))
        mid = dp[w] * max(1, fib(w - 1)) * max(1, fib(W - 1 - w - 1))
        newDp[w] = (left + mid + right) % MOD
    dp = newDp

print(dp[K])

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H, W, K = Scanner.map_int()

    L = []
    for i in range(1 << (W - 1)):
        l = [False for _ in range(W - 1)]
        for j in range(W-1):
            if i >> j & 1:
                l[j] = True
        for j in range(W - 2):
            if l[j] and l[j + 1]:
                break
        else:
            L.append(l)

    m = [[0 for _ in range(W)]for _ in range(W)]
    if W == 1:
        m[0][0] = 1
    else:
        for l in L:
            for w in range(W):
                k = w
                if w < W - 1 and l[w]:
                    k = k + 1
                elif w - 1 >= 0 and l[w - 1]:
                    k = k - 1
                m[w][k] += 1
    dp = [[0 for _ in range(W)]for _ in range(H + 1)]
    dp[0][0] = 1

    for h in range(H):
        for w in range(W):
            for i in range(W):
                dp[h + 1][w] += m[w][i] * dp[h][i]
                dp[h + 1][w] %= MOD
    print(dp[H][K - 1])


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
h,w,k=map(int,input().split())
mod=10**9+7
R=[[],[1],[1,1],[2,1,2],[3,2,2,3],[5,3,4,3,5],[8,5,6,6,5,8],[13,8,10,9,10,8,13]]
T=[1,2,3,5,8,13,21,34]
r=R[w-1]
t=T[w-1]
A=[0]*w
A[0]=1
if w==1:
    print(1)
else:
    for i in range(h):
        C=[0]*w
        for i in range(w):
            if i==0:
                C[0]+=(t-r[0])*A[0]
                C[1]+=r[0]*A[0]
            elif i==w-1:
                C[w-1]+=(t-r[w-2])*A[w-1]
                C[w-2]+=r[w-2]*A[w-1]
            else:
                C[i-1]+=r[i-1]*A[i]
                C[i]+=(t-r[i-1]-r[i])*A[i]
                C[i+1]+=r[i]*A[i]
        for i in range(w):
            C[i]%=mod
        A=C
    print(A[k-1])

Solution (Python):

mod=10**9+7
h,w,K=map(int,input().split())
dp=[[0]*w for j in range(h+1)]
dp[0][0]=1
for i in range(1,h+1):
    for k in range(2**(w-1)):
        for l in range(w-2):
            if ((k>>l)&1) and ((k>>(l+1))&1):
                break
        else:
            for l in range(w):
                if l==0:
                    if ((k>>l)&1):
                        dp[i][l+1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                elif l==w-1:
                    if ((k>>(l-1))&1):
                        dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                else:
                    if ((k>>l)&1) or ((k>>(l-1))&1):
                        if ((k>>l)&1):
                            dp[i][l+1]+=dp[i-1][l]
                        else:
                            dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
            dp[i][l]%=mod
print(dp[h][K-1]%mod)

Solution (Python):

mod=10**9+7
h,w,K=map(int,input().split())
dp=[[0]*w for j in range(h+1)]
dp[0][0]=1
for i in range(1,h+1):
    for k in range(2**(w-1)):
        for l in range(w-2):
            if ((k>>l)&1) and ((k>>(l+1))&1):
                break
        else:
            for l in range(w):
                if l==0:
                    if ((k>>l)&1):
                        dp[i][l+1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                elif l==w-1:
                    if ((k>>(l-1))&1):
                        dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                else:
                    if ((k>>l)&1) or ((k>>(l-1))&1):
                        if ((k>>l)&1):
                            dp[i][l+1]+=dp[i-1][l]
                        else:
                            dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
            
print(dp[h][K-1]%mod)

Solution (Python):
MOD = 10**9+7
H, W, K = map(int, input().split())
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for k in range(1<<(W-1)):
            
            ok = True
            for l in range(W-2):
                if (k>>l)&1 and (k>>(l+1))&1:
                    ok = False
            if ok:
                if j>=1 and (k>>(j-1))&1:
                    
                    dp[i+1][j-1] += dp[i][j]
                    dp[i+1][j-1] %= MOD
                elif j<W-1 and (k>>j)&1:
                    
                    dp[i+1][j+1] += dp[i][j]
                    dp[i+1][j+1] %= MOD
                else:
                    
                    dp[i+1][j] += dp[i][j]
                    dp[i+1][j] %= MOD
print(dp[H][K-1])

Solution (Python):
H, W, K  = map(int, input().split())
MOD = 10**9+7



L = [0]*(W-1)
row = 0
for i in range(2**(W-1)):
  LL = format(i, '08b')
  Lf = 0
  for j in range(len(LL)-1):
    if LL[j] == "1" and LL[j+1] == "1":
      Lf = 1
  if Lf == 0:
    row += 1
    LL = LL[8-(W-1):]
    for k in range(W-1):
      if LL[k] == "1":
        L[k] += 1
  
    


B = [] 
for _ in range(W):
  B.append([0,0,0])

for i in range(W):
  if i != 0:
    B[i][0] = L[i-1]
  else:
    B[i][0] = 0
  
  if i != W-1:
    B[i][2] = L[i]
  else:
    B[i][2] = 0

  B[i][1] = row-B[i][0]-B[i][2] 


A = [[0]*(W+2)]
for _ in range(H):
  A.append([0]*(W+2))

A[0][1] = 1

for i in range(H):
  for j in range(1,W+1):
    A[i+1][j-1] += A[i][j] * (B[j-1][0])
    A[i+1][j] += A[i][j] * (B[j-1][1])
    A[i+1][j+1] += A[i][j] * (B[j-1][2])

print(A[H][K]%MOD)

Solution (Python):
h,w,k = map(int,input().split())
if w == 1:
  print(1)
  exit()
a = [0]*(w+2)
a[1] = 1
f = [0]*(w-1)
p = 0
q = 1
for i in range(w-1):
  f[i] = p+q
  q = p + q
  p = q - p  
f.append(1)
b = []
mod = 10**9+7
for i in range(w):
  if i == 0:
    b.append([0,f[w-2],f[w-3]])
  elif i == w-1:
    b.append([f[w-3],f[w-2],0])
  else:
    b.append([f[i-2]*f[w-i-2],f[i-1]*f[w-i-2],f[i-1]*f[w-i-3]])
for _ in range(h):
  newa = [0]*(w+2)
  for i in range(1,w+1):
    newa[i] = (a[i-1]*b[i-1][0]+a[i]*b[i-1][1]+a[i+1]*b[i-1][2])%mod
  a = newa
print(a[k])

Solution (Python):

MOD = 10**9+7
H,W,K = map(int,input().split())
K -= 1
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for bit in range(1<<(W-1)):
            ok = True
            for k in range(W-2):
                if bit & (1 << k) and bit & (1 << (k+1)):
                    ok = False
            if not ok:
                continue
            nj = j
            if bit & (1<<j):
                nj = j+1
            elif j>0 and bit & (1<<(j-1)):
                nj = j-1
            dp[i+1][nj] += dp[i][j]
            dp[i+1][nj] %= MOD

print(dp[H][K]%MOD)