提出 #53547522


ソースコード 拡げる

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

# dp[i][j] := i 行 j 列目に番号 1 が存在する通り数
dp = [[0]*(W + 1) for _ in range(H + 1)]
dp[0][1] = 1

for i in range(H):
    for S in range(1 << (W - 1)):
        is_ok = True
        for j in range(W - 2):
            if (S >> j) & 1 and (S >> (j + 1)) & 1:
                is_ok = False
                break
        if not is_ok:
            continue
        amida = [j for j in range(W)]
        for j in range(W - 1):
            if (S >> j) & 1:
                amida[j], amida[j + 1] = amida[j + 1], amida[j]
        for j in range(W):
            dp[i + 1][j + 1] += dp[i][amida[j] + 1]
            dp[i + 1][j + 1] %= mod

# print(*dp, sep="\n")
print(dp[H][K])

提出情報

提出日時
問題 D - Number of Amidakuji
ユーザ ryusuke_h
言語 Python (PyPy 3.10-v7.3.12)
得点 400
コード長 766 Byte
結果 AC
実行時間 70 ms
メモリ 82268 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 6
AC × 16
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, sample_06.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, sample_06.txt
ケース名 結果 実行時間 メモリ
in01.txt AC 70 ms 81756 KiB
in02.txt AC 70 ms 82268 KiB
in03.txt AC 69 ms 81608 KiB
in04.txt AC 69 ms 82068 KiB
in05.txt AC 70 ms 81952 KiB
in06.txt AC 63 ms 81520 KiB
in07.txt AC 55 ms 76464 KiB
in08.txt AC 68 ms 81980 KiB
in09.txt AC 61 ms 81516 KiB
in10.txt AC 70 ms 82268 KiB
sample_01.txt AC 55 ms 76172 KiB
sample_02.txt AC 55 ms 76760 KiB
sample_03.txt AC 55 ms 76556 KiB
sample_04.txt AC 54 ms 76468 KiB
sample_05.txt AC 56 ms 76408 KiB
sample_06.txt AC 69 ms 81844 KiB