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):
import sys
readline = sys.stdin.readline











H,W,K = map(int,readline().split())
DIV = 1000000007


LINE = [-1] * (W - 1)
for i in range(W - 1):
  
  dp = [[0] * 2 for j in range(W - 1)]
  if i == 0:
    dp[0][0] = 0
    dp[0][1] = 1
  else:
    dp[0][0] = 1
    dp[0][1] = 1
  for j in range(1, W - 1):
    if j == i:
      dp[j][0] = 0
      dp[j][1] = dp[j - 1][0]
    else:
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
      dp[j][1] += dp[j - 1][0]
  LINE[i] = dp[-1][0] + dp[-1][1]
  LINE[i] %= DIV

POINT = [-1] * W


for i in range(W):
  
  dp = [[0] * 2 for j in range(W)]
  if i - 1 == 0 or i == 0:
    dp[0][0] = 1
    dp[0][1] = 0
  else:
    dp[0][0] = 1
    dp[0][1] = 1
  for j in range(1, W):
    if j == i - 1 or j == i:
      dp[j][1] = 0
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
    else:
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
      if j == W - 1:
        dp[j][1] = 0
      else:
        dp[j][1] += dp[j - 1][0]
  POINT[i] = dp[-1][0] + dp[-1][1]
  POINT[i] %= DIV
  



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

for i in range(1, len(dp)):
  for j in range(W):
    
    if j - 1 >= 0:
      dp[i][j] += dp[i - 1][j - 1] * LINE[j - 1]
    dp[i][j] += dp[i - 1][j] * POINT[j]
    if j + 1 < W:
      dp[i][j] += dp[i - 1][j + 1] * LINE[j]
      
    dp[i][j] %= DIV
    
print(dp[H][K - 1])

Solution (Python):
from itertools import combinations

def getval():
    h,w,k = map(int,input().split())
    return h,w,k

def main(h,w,goal):
    dp = [0 for i in range(w)]
    dp[0] = 1
    mod = 10**9 + 7
    for i in range(h):
        temp = [0 for i in range(w)]
        for j in range(w):
            for comb in combinations(range(w-1),j):
                arr = [k for k in comb]
                arr.sort()
                flag = False
                for k in range(len(arr)-1):
                    if arr[k]+1==arr[k+1]:
                        flag = True
                        break
                if flag:
                    continue
                for k in range(w):
                    if k in arr:
                        temp[k+1] += dp[k]
                        temp[k+1] %= mod
                    elif k-1 in arr:
                        temp[k-1] += dp[k]
                        temp[k-1] %= mod
                    else:
                        temp[k] += dp[k]
                        temp[k] %= mod
        dp = temp
    print(dp[goal-1]%mod)
                
                
if __name__=="__main__":
    h,w,k= getval()
    main(h,w,k)

Solution (Python):










def solve(H, W, K):
    mod = 10 ** 9 + 7
    dp = [[0] * W for _ in range(H + 1)]
    dp[0][0] = 1
    fibo = [1, 2, 3, 5, 8, 13, 21]
    for h in range(H):
        for w in range(W):
            if dp[h][w] == 0:
                continue
            for i in range(3):
                new_w = w - 1 + i
                if not 0 <= new_w < W:
                    continue
                l, r = min(w, new_w), max(w, new_w)
                tmp = fibo[max(l - 1, 0)] * fibo[max(W - 1 - (r + 1), 0)]
                dp[h + 1][new_w] += dp[h][w] * tmp
                dp[h + 1][new_w] %= mod
    print(dp[-1][K - 1])


if __name__ == '__main__':
    H, W, K = map(int, input().split())
    solve(H, W, K)

Solution (Python):










def solve(H, W, K):
    mod = 10 ** 9 + 7
    dp = [[0] * W for _ in range(H + 1)]
    dp[0][0] = 1
    for h in range(H):
        for w in range(W):
            if dp[h][w] == 0:
                continue
            for i in range(3):
                new_w = w - 1 + i
                if not 0 <= new_w < W:
                    continue

                def cnt_tmp(n, r, l, flg):
                    re = 0
                    if n >= W - 2:
                        if r <= n <= l:
                            return 1
                        if flg:
                            return 1
                        else:
                            return 2
                    if r <= n <= l:
                        return cnt_tmp(n + 1, r, l, False)
                    re += cnt_tmp(n + 1, r, l, False)
                    re += cnt_tmp(n + 1, r, l, True) if not flg else 0
                    return re

                tmp = cnt_tmp(0, min(w, new_w) - 1, max(w, new_w), False)
                dp[h + 1][new_w] += dp[h][w] * tmp
                dp[h + 1][new_w] %= mod
    
    
    print(dp[-1][K - 1])


if __name__ == '__main__':
    H, W, K = map(int, input().split())
    solve(H, W, K)

Solution (Python):

import sys
import itertools

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

if w==1:
    print(1)
    sys.exit()
    
mod=10**9+7

ww=[]
for i in itertools.product([0,1], repeat=w-1):
    yn=""
    for wi in range(w-2):
        if i[wi]==1 and i[wi+1]==1:
            yn="no"
            break
    if yn=="" :
        ww.append(i)

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

for i in range(h):
    for wi in ww:
        j=0
        if wi[j]==1:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j+1])%mod
        else:    
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod

        for j in range(1,w-1):
            if wi[j-1]==1:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j-1])%mod
            elif wi[j]==1:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j+1])%mod
            else:    
                dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod
        j=w-1
        if wi[j-1]==1:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j-1])%mod
        else:    
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod
                
print(dp[h][k-1])

Solution (Python):
"""
dp[i][j] => i回目の移動が終了したタイミングでj列目にいる場合の数
dp[i][j] 
= dp[i-1][j-1]*(j-1列目とj列目の間に横棒があるような横棒の配置パターン数)
+ dp[i-1][j+1]*(j+1列目とj列目の間に横棒があるような横棒の配置パターン数)
+ dp[i-1][j]*(j列目の両サイドに横棒がないような横棒の配置パターン数)
"""

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

"""
横棒の配置パターンを前計算しておく
patternA[i] => i列目とi-1列目の間に横棒があるような横棒の配置パターン数
patternB[i] => i列目の両サイドに横棒がないような横棒の配置パターン数
"""
patternA = [0]*(W)
patternB = [0]*(W)
for i in range(2**(W-1)):
    pattern = format(i,"0"+str(W-1)+"b")
    for j in range(1,W-1):
        if pattern[j] == "1" and pattern[j-1]=="1":
            break
    else:
        for j in range(W-1):
            if pattern[j] == "1":
                patternA[j+1] += 1

        for j in range(W):
            if j == 0:
                if pattern[j] == "0":
                    patternB[j] += 1
            elif 0 < j < W-1:
                if pattern[j-1] == "0" and pattern[j] == "0":
                    patternB[j] += 1
            elif j == W-1:
                if pattern[j-1] == "0":
                    patternB[j] += 1

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

for i in range(1,H+1):
    for j in range(W):
        
        if j > 0:
            dp[i][j] += dp[i-1][j-1]*patternA[j]%mod
        
        if j < W-1:
            dp[i][j] += dp[i-1][j+1]*patternA[j+1]%mod
        
        
        dp[i][j] += dp[i-1][j]*patternB[j]%mod

        dp[i][j] %= mod

print(dp[-1][K-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


def fib(n):
    if n <= 1:
        return 1
    return fib(n-1) + fib(n-2)


for i in range(1, H+1):
    for j in range(W):
        left = j
        right = W - j - 1

        dp[i][j] = dp[i-1][j] * fib(left) * fib(right)

        if j > 0:
            dp[i][j] += dp[i-1][j-1] * fib(left-1) * fib(right)

        if j < W-1:
            dp[i][j] += dp[i-1][j+1] * fib(left) * fib(right - 1)

        dp[i][j] %= mod

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

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

    if w == 1:
        print(1)
        exit()
    if w == 2:
        print(pow(2, h-1, mod))
        exit()

    k -= 1

    fibo = [1, 2, 3, 5, 8, 13, 21]

    dp = [0] * w
    dp[0] = 1
    for _ in range(h):
        new_dp = [0] * w
        new_dp[0] = (dp[0] * fibo[w-2] + dp[1] * fibo[w-3]) % mod
        new_dp[1] = (dp[0] * fibo[w-3]) % mod
        new_dp[w-1] = (dp[w-1] * fibo[w-2] + dp[w-2] * fibo[w-3]) % mod
        new_dp[w-2] += (dp[w-1] * fibo[w-3]) % mod
        for i in range(1, w-1):
            new_dp[i] += ((fibo[i-1] * fibo[w-i-2]) * dp[i]) % mod
        for i in range(1, w-2):
            new_dp[i] += (fibo[i-1] * fibo[w-i-3]) * dp[i+1]
            new_dp[i] %= mod
            new_dp[i+1] += (fibo[i-1] * fibo[w-i-3]) * dp[i]
            new_dp[i+1] %= mod
        dp = new_dp

    print(dp[k] % mod)

main()

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

    if w == 1:
        print(1)
        exit()
    if w == 2:
        print(pow(2, h-1, mod))
        exit()

    k -= 1

    fibo = [1, 2, 3, 5, 8, 13, 21]

    dp = [0] * w
    dp[0] = 1
    for _ in range(h):
        new_dp = [0] * w
        new_dp[0] = (dp[0] * fibo[w-2] + dp[1] * fibo[w-3]) % mod
        new_dp[1] = (dp[0] * fibo[w-3]) % mod
        new_dp[w-1] = (dp[w-1] * fibo[w-2] + dp[w-2] * fibo[w-3]) % mod
        new_dp[w-2] += (dp[w-1] * fibo[w-3]) % mod
        for i in range(1, w-1):
            new_dp[i] += ((fibo[i-1] * fibo[w-i-2]) * dp[i]) % mod
        for i in range(1, w-2):
            new_dp[i] += (fibo[i-1] * fibo[w-i-3]) * dp[i+1]
            new_dp[i] %= mod
            new_dp[i+1] += (fibo[i-1] * fibo[w-i-3]) * dp[i]
            new_dp[i+1] %= mod
        dp = new_dp

    print(dp[k] % mod)

main()

Solution (Python):


import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
H,W,K = map(int,readline().split())
facts = [1,1,2,3,5,8,13,21,34]






dp = [0] * W
dp[0] = 1
for _ in range(H):
    ndp = [0]*W
    for w in range(W):
        ndp[w] += dp[w] * facts[w] * facts[W-w-1]
        if w > 0:
            ndp[w] += dp[w-1] * facts[w-1] * facts[W-w-1] 
        if w < W-1:
            ndp[w] += dp[w+1] * facts[w] * facts[W-w-2]
        ndp[w] %= MOD
    dp = ndp
    
print(dp[K-1])

Solution (Python):
H,W,K = map(int,input().split())
mod = 10**9+7
dp = W*[0]
dp[0] = 1
fib = [1,1,2,3,5,8,13,21,34,55,89]

for h in range(H):
  t = W*[0]
  for w in range(W):
    if 0<w:
      t[w]+=dp[w-1]*fib[w-1]*fib[W-w-1]
    t[w]+=dp[w]*fib[w]*fib[W-w-1]
    
    if w<W-1:
      t[w]+=dp[w+1]*fib[w]*fib[W-w-2]
    t[w]%=mod
  dp = t

print(dp[K-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 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

            jj = j
            if j > 0 and bit & (1 << (j-1)):
                jj -= 1
            elif j < W - 1 and bit & (1 << j):
                jj += 1
            dp[i+1][jj] += dp[i][j]
            dp[i+1][jj] %= mod


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

Solution (Python):
"""
memo1[i] => i列目とi+1列目の間に横棒があるような場合の数
memo2[i] => i列目の両サイドに横棒がないような場合の数
"""

H,W,K = map(int,input().split())
if W == 1:
    print(1)
    exit()
mod = 10**9 +7
memo1 = [0]*(W-1)
memo2 = [0]*W
for i in range(2**(W-1)):
    
    binI = format(i,"0"+str(W-1)+"b")
    
    for j in range(W-2):
        if binI[j]=="1" and binI[j+1]=="1":
            break
    else:
        for j in range(W-1):
            if binI[j] == "1":
                memo1[j] += 1
        if binI[0] == "0":
            memo2[0] += 1
        if binI[-1] == "0":
            memo2[-1] += 1
        for j in range(1,W-1):
            if binI[j-1]=="0" and binI[j]=="0":
                memo2[j] += 1



dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        
        dp[i+1][j] += dp[i][j]*memo2[j]
        dp[i+1][j] %= mod

        
        if j != W-1:
            dp[i+1][j+1] += dp[i][j]*memo1[j]
            dp[i+1][j+1] %= mod

        
        if j != 0:
            dp[i+1][j-1] += dp[i][j]*memo1[j-1]
            dp[i+1][j-1] %= mod

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

Solution (Python):
import sys

h, w, k = map(int, input().split())
mod = 10 ** 9 + 7
if w == 1:
    print(1)
    sys.exit()
row = [0 for i in range(w + 1)]
row[0] = 1
row[1] = 1
for i in range(w - 1):
    row[i + 2] = row[i + 1] + row[i]

dp = [[0 for i in range(w)] for j in range(h + 1)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if j == 0:
            dp[i + 1][j] = dp[i][j] * row[w - 1] + dp[i][j + 1] * row[w - 2]
            dp[i + 1][j] %= mod
        elif j == w - 1:
            dp[i + 1][j] = dp[i][j] * row[w - 1] + dp[i][j - 1] * row[w - 2]
            dp[i + 1][j] %= mod
        else:
            dp[i + 1][j] = dp[i][j - 1] * row[j - 1] * row[w - j - 1] + dp[i][j] * row[j] * row[w - j - 1] + dp[i][j + 1] * row[j] * row[w - j - 2]
            dp[i + 1][j] %= mod
print(dp[h][k - 1])

Solution (Python):
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


mod = 10 ** 9 + 7


def main():

    H, W, K = in_nn()

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

    comb_t = itertools.product(range(2), repeat=W - 1)
    comb = [[0 for _ in range(3)] for _ in range(W)]

    for c in comb_t:

        f = True
        for i in range(W - 2):
            if c[i] == c[i + 1] == 1:
                f = False
                break

        if f:
            for i in range(W):

                if i - 1 >= 0 and c[i - 1] == 1:
                    comb[i][0] += 1
                elif i < W - 1 and c[i] == 1:
                    comb[i][2] += 1
                else:
                    comb[i][1] += 1

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

    for y in range(H):
        for x in range(W):

            now = dp[y][x]
            dp[y + 1][x] += now * comb[x][1]
            dp[y + 1][x] %= mod
            if 0 <= x - 1 < W:
                dp[y + 1][x - 1] += now * comb[x][0]
                dp[y + 1][x - 1] %= mod
            if 0 <= x + 1 < W:
                dp[y + 1][x + 1] += now * comb[x][2]
                dp[y + 1][x + 1] %= mod

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


if __name__ == '__main__':
    main()

Solution (Python):
"""
15,8,5の場合：
何回右に移動するか、何回左に移動するか。
dp[i][j] => i回目下降が終わった時点で、j列目にいる場合の数
memo[j] => 特定の高さを見たときに、j列目とj+1列目の間に横棒があるような横棒配置パターン数
memo2[j] => j列目の左右に横棒がないような場合の数
"""
mod = 10**9 +7
H,W,K = map(int,input().split())
if W == 1:
    print(1)
    exit()
memo = [0]*(W-1)
memo2 = [0]*(W-1)
cnt = 0
for i in range(2**(W-1)):
    binI = format(i,"0"+str(W-1)+"b")
    
    for j in range(W-2):
        if binI[j] == "1" and binI[j+1] == "1":
            break
    else:
        cnt += 1
        for j in range(W-1):
            if binI[j] == "1":
                memo[j] += 1
        for j in range(1,W-1):
            if binI[j-1]=="0" and binI[j] =="0":
                memo2[j] += 1
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        
        if j != W-1:
            dp[i+1][j+1] += memo[j]*dp[i][j]%mod
            dp[i+1][j+1] %= mod
        
        if j != 0:
            dp[i+1][j-1] += memo[j-1]*dp[i][j]%mod
            dp[i+1][j-1] %= mod
        
        if j == 0:
            dp[i+1][j] += (cnt-memo[j])*dp[i][j]%mod
        elif j == W-1:
            dp[i+1][j] += (cnt-memo[j-1])*dp[i][j]%mod
        else:
            dp[i+1][j] += memo2[j]*dp[i][j]%mod
        dp[i+1][j]%=mod

print(dp[-1][K-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 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 not ok:
                continue

            if j > 0 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[-1][K - 1])

Solution (Python):
h, w, k = map(int, input().split())
dp = [0] * w
mod = 10 ** 9 + 7

comb = []
for bit in range(1 << w - 1):
    ok = True
    for j in range(w - 2):
        if bit >> j & 1 and bit >> j + 1 & 1:
            ok = False
    if ok:
        comb.append(bit)

dp[0] = 1
for i in range(h):
    next = [0] * w
    for bit in comb:
        moved = [False] * w
        for j in range(w):
            if bit >> j & 1:
                next[j + 1] += dp[j]
                next[j] += dp[j + 1]
                moved[j] = moved[j + 1] = True
            elif not moved[j]:
                next[j] += dp[j]
    dp = next
print(dp[k - 1] % mod)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

H,W,K = MI()
mod = 10**9+7

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

fib = [1,1,2,3,5,8,13,21]  

dp = [[0]*(W+1) for _ in range(H+1)]  
dp[0][1] = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        if j == 1:
            dp[i][j] = dp[i-1][j+1]*fib[W-j-1] + dp[i-1][j]*fib[W-j]
            dp[i][j] %= mod
        elif j == W:
            dp[i][j] = dp[i-1][j-1]*fib[j-2] + dp[i-1][j]*fib[j-1]
            dp[i][j] %= mod
        else:
            dp[i][j] = dp[i-1][j-1]*fib[j-2]*fib[W-j] + dp[i-1][j+1]*fib[j-1]*fib[W-j-1] + dp[i-1][j]*fib[W-j]*fib[j-1]
            dp[i][j] %= mod

print(dp[H][K])

Solution (Python):
import sys

h, w, k = map(int, input().split())
MOD = 1000000007

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

fn = [1, 1, 2, 3, 5, 8, 13, 21, 34]

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

for i in range(1, h + 1):
    for j in range(w):
        dp[i][j] = dp[i - 1][j] * fn[j] * fn[w - j - 1]
        if j < w - 1:
            dp[i][j] += dp[i - 1][j + 1] * fn[j] * fn[w - j - 2]
        if 0 < j:
            dp[i][j] += dp[i - 1][j - 1] * fn[j - 1] * fn[w - j - 1]
        dp[i][j] %= MOD

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

Solution (Python):
MOD = 10 ** 9 + 7
h, w, k = [int(x) for x in input().split()]
dp = [[0] * w for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
    for b in range(1 << (w-1)):
        ok = True
        for s in range(w-2):
            if b >> s & 1 and b >> (s+1) & 1:
                ok = False
        if ok:            
            for j in range(w):
                if j > 0 and b >> (j-1) & 1:
                    dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
                elif j+1 < w and b >> j & 1:
                    dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD
                else:
                    dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD

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

Solution (Python):
h, w, k = map(int, input().split())
dp = [0] * w
mod = 10 ** 9 + 7

dp[0] = 1
for i in range(h):
    next = [0] * w
    for bit in range(1 << w - 1):
        ok = True
        for j in range(w - 2):
            if bit >> j & 1 and bit >> j + 1 & 1:
                ok = False
        if ok:
            moved = [False] * w
            for j in range(w):
                if bit >> j & 1:
                    next[j + 1] += dp[j]
                    next[j] += dp[j + 1]
                    moved[j] = moved[j + 1] = True
                elif not moved[j]:
                    next[j] += dp[j]
    dp = next
print(dp[k - 1] % mod)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  

H,W,K = MI()
mod = 10**9+7

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

fib = [1,1,2,3,5,8,13,21,34]

dp = [[0]*(W+1) for _ in range(H+1)]
dp[0][1] = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        if W == 2:
            if j == 1:
                dp[i][j] = dp[i-1][j] + dp[i-1][j+1]
                dp[i][j] %= mod
            else:
                dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
                dp[i][j] %= mod
        else:
            if j == 1:
                dp[i][j] = dp[i-1][j+1]*fib[W-2] + dp[i-1][j]*fib[W-j]
                dp[i][j] %= mod
            elif j == W:
                dp[i][j] = dp[i-1][j-1]*fib[W-2] + dp[i-1][j]*fib[j-1]
                dp[i][j] %= mod
            else:
                dp[i][j] = dp[i-1][j-1]*fib[j-2]*fib[W-j] + dp[i-1][j+1]*fib[j-1]*fib[W-j-1] + dp[i-1][j]*(fib[W-j]*fib[j-1])
                dp[i][j] %= mod

print(dp[H][K])

Solution (Python):
h,w,k = map(int, input().split())
remv = [1,1,2,3,5,8,13,21]

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

MOD = 10**9+7
for i in range(h):
    for wi in range(w):
        left = wi
        right = w-wi-1
        com = remv[left] * remv[right]
        dp[i+1][wi] += dp[i][wi]*com
        dp[i+1][wi] %= MOD

        if wi > 0:
            left = wi-1
            right = w-wi-1
            com = remv[left] * remv[right]
            dp[i+1][wi-1] += dp[i][wi]*com
            dp[i+1][wi-1] %= MOD

        if wi < w-1:
            left = wi
            right = w-(wi+1)-1
            com = remv[left] * remv[right]
            dp[i+1][wi+1] += dp[i][wi]*com
            dp[i+1][wi+1] %= MOD


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

Solution (Python):
import itertools

h, w, k = map(int, input().split())
mod = 10**9 + 7





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


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

bridges = list(itertools.product([0, 1], repeat=w - 1))


for i in range(h):
    for bridge in bridges:

        
        tf = True
        for j in range(w - 2):
            if bridge[j] == 1 and bridge[j + 1] == 1:
                tf = False
                break
        if tf == False:
            continue

        for j in range(w):
            
            if j == 0:
                
                if bridge[0] == 1:
                    dp[i + 1][j] += dp[i][j + 1]
                
                else:
                    dp[i + 1][j] += dp[i][j]

            
            elif j == w - 1:
                
                if bridge[-1] == 1:
                    dp[i + 1][j] += dp[i][j - 1]
                
                else:
                    dp[i + 1][j] += dp[i][j]

            
            else:
                
                if bridge[j - 1] == 0 and bridge[j] == 0:
                    dp[i + 1][j] += dp[i][j]
                
                elif bridge[j - 1] == 1 and bridge[j] == 0:
                    dp[i + 1][j] += dp[i][j - 1]
                
                elif bridge[j - 1] == 0 and bridge[j] == 1:
                    dp[i + 1][j] += dp[i][j + 1]

            dp[i + 1][j] %= mod

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

Solution (Python):
H, W, K = map(int, input().split())
MOD, p, cnt = 10**9+7, [0]*W, 0
for bit in range(1<<(W-1)):
    s0 = bit&1
    flg=True
    for w in range(1, W-1):
        if (bit>>w)&1 and s0 == 1:flg=False; break
        s0 = (bit>>w)&1
    if flg:
        cnt += 1
        for w in range(W - 1):
            if (bit >> w)&1:p[w] += 1
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for w in range(W):
        if w:
            dp[h+1][w-1] += dp[h][w]*p[w-1]
            dp[h+1][w-1] %= MOD
        if w-(W - 1):
            dp[h+1][w+1] += dp[h][w]*p[w]
            dp[h+1][w+1] %= MOD
        dp[h+1][w]+=dp[h][w]*(cnt-p[w-1]-p[w])
        dp[h+1][w]%=MOD
print(dp[H][K-1])

Solution (Python):
h,w,k=map(int,input().split())
dp=[[0 for _ in range(w)]for _ in range(h+1)]
dp[0][0]=1
mod=10**9+7
for i in range(h):
    for bit in range(2**(w-1)):
        bit=bin(bit)[2:].zfill(w-1)
        f=0
        for j in range(w-2):
            if bit[j]=='1' and bit[j+1]=='1':
                f=1
                break
        if f:
            continue
        for j in range(w):
            if j==0:
                dp[i+1][j]+=dp[i][j+1] if bit[0]=='1' else dp[i][j]
            elif j==w-1:
                dp[i+1][j]+=dp[i][j-1] if bit[-1]=='1' else dp[i][j]
            else:
                dp[i+1][j]+=dp[i][j]*(bit[j-1]=='0' and bit[j]=='0')
                dp[i+1][j]+=dp[i][j-1]*(bit[j-1]=='1')
                dp[i+1][j]+=dp[i][j+1]*(bit[j]=='1')
            dp[i+1][j]%=mod
print(dp[-1][k-1])

Solution (Python):
H, W, K = map(int, input().split())
W2 = W-1
c = [0] * (W2+1)
cnt = 0
MOD = 10**9 + 7
for bit in range(1 << W2):
    s0 = bit&1
    flg=True
    for i in range(1, W2):
        if (bit>>i)&1 and s0 == 1:
            flg = False
            break
        s0 = (bit>>i)&1
    if flg:
        cnt += 1
        for i in range(W2):
            if (bit >> i)&1:
                c[i] += 1
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for i in range(W):
        if i != 0:
            dp[h+1][i-1] += dp[h][i]*c[i-1]
            dp[h+1][i-1] %= MOD
        if i != W-1:
            dp[h+1][i+1] += dp[h][i]*c[i]
            dp[h+1][i+1] %= MOD
        dp[h+1][i] += dp[h][i]*(cnt-c[i-1]-c[i])
        dp[h+1][i] %= MOD
print(dp[H][K-1])

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

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

OK = [0, 1, 1, 2, 3, 5, 8, 13]
NG = [0, 1, 2, 3, 5, 8, 13, 21]

if W == 1:
  print(dp[K-1])
else:
  for _ in range(H):
    temp = dp[:]
    for i in range(W):
      if i == 0:
        dp[i] = temp[i] * NG[W-1-i] + temp[i+1] * OK[W-1-i]
      elif i == W-1:
        dp[i] = temp[i-1] * OK[i] + temp[i] * NG[i]
      else:  
        dp[i] = temp[i-1] * OK[i] * NG[W-1-i] + temp[i] * NG[i] * NG[W-1-i] + temp[i+1] * NG[i] * OK[W-1-i]
      dp[i] %= mod
  print(dp[K-1])

Solution (Python):
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())

    A = product((0, 1), repeat=W - 1)
    B = []
    for bars in A:
        ok = True
        for i in range(W - 2):
            if bars[i] and bars[i + 1]:
                ok = False
                break
        if ok:
            B.append(bars)

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

    for _ in range(H):
        dp, dp_prev = [0] * W, dp
        for bars in B:
            for i in range(W):
                if i > 0 and bars[i - 1]:
                    dp[i - 1] = (dp[i - 1] + dp_prev[i]) % MOD
                elif i < W - 1 and bars[i]:
                    dp[i + 1] = (dp[i + 1] + dp_prev[i]) % MOD
                else:
                    dp[i] = (dp[i] + dp_prev[i]) % MOD

    print(dp[K - 1])

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())

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

    for _ in range(H):
        dp, dp_prev = [0] * W, dp
        for mask in range(1 << (W - 1)):
            ok = True
            for i in range(W - 2):
                if mask & (1 << i) and mask & (1 << (i + 1)):
                    ok = False
                    break
            if not ok:
                continue
            for i in range(W):
                if i > 0 and mask & (1 << (i - 1)):
                    dp[i - 1] = (dp[i - 1] + dp_prev[i]) % MOD
                elif i < W - 1 and mask & (1 << i):
                    dp[i + 1] = (dp[i + 1] + dp_prev[i]) % MOD
                else:
                    dp[i] = (dp[i] + dp_prev[i]) % MOD

    print(dp[K - 1])

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())

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

    for _ in range(H):
        dp, dp_prev = [0] * W, dp
        for mask in range(1 << (W - 1)):
            ok = True
            for i in range(W - 2):
                if mask & (1 << i) and mask & (1 << (i + 1)):
                    ok = False
            if not ok:
                continue
            for i in range(W):
                if i > 0 and mask & (1 << (i - 1)):
                    dp[i - 1] = (dp[i - 1] + dp_prev[i]) % MOD
                elif i < W - 1 and mask & (1 << i):
                    dp[i + 1] = (dp[i + 1] + dp_prev[i]) % MOD
                else:
                    dp[i] = (dp[i] + dp_prev[i]) % MOD

    print(dp[K - 1])

    return


if __name__ == '__main__':
    main()