結果

問題 No.554 recurrence formula
ユーザー magurogumamaguroguma
提出日時 2017-09-24 01:45:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 327 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 10,724 KB
実行使用メモリ 11,936 KB
最終ジャッジ日時 2023-08-09 00:33:02
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,796 KB
testcase_01 AC 16 ms
8,840 KB
testcase_02 AC 17 ms
8,708 KB
testcase_03 AC 18 ms
8,860 KB
testcase_04 AC 17 ms
8,748 KB
testcase_05 AC 17 ms
8,664 KB
testcase_06 AC 17 ms
8,908 KB
testcase_07 AC 17 ms
8,848 KB
testcase_08 AC 17 ms
8,728 KB
testcase_09 AC 17 ms
8,792 KB
testcase_10 AC 18 ms
8,776 KB
testcase_11 AC 19 ms
9,104 KB
testcase_12 AC 19 ms
8,708 KB
testcase_13 AC 20 ms
9,124 KB
testcase_14 AC 19 ms
8,984 KB
testcase_15 AC 20 ms
9,124 KB
testcase_16 AC 21 ms
9,112 KB
testcase_17 AC 20 ms
9,112 KB
testcase_18 AC 19 ms
9,060 KB
testcase_19 AC 55 ms
11,936 KB
testcase_20 AC 55 ms
11,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys

N = int(input())
M = 10**9 + 7

dp = [0] * (10**5 + 1)
def recurrence(n):
    if n==0:
        dp[n] = 0
    elif n==1:
        dp[n] = 1
    elif n==2:
        dp[n] = 2
    else:
        dp[n] = (n*dp[n-1] + dp[n-2]) % M

for i in range(N+1):
    recurrence(i)

print((dp[N]-dp[N-2]) % M)
0