結果

問題 No.554 recurrence formula
ユーザー magurogumamaguroguma
提出日時 2017-09-24 01:03:12
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 539 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 10,528 KB
実行使用メモリ 12,036 KB
最終ジャッジ日時 2023-08-09 00:31:05
合計ジャッジ時間 1,723 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,712 KB
testcase_01 AC 18 ms
8,736 KB
testcase_02 AC 17 ms
8,740 KB
testcase_03 AC 18 ms
8,740 KB
testcase_04 AC 17 ms
8,876 KB
testcase_05 AC 17 ms
8,668 KB
testcase_06 AC 17 ms
8,848 KB
testcase_07 AC 17 ms
8,860 KB
testcase_08 AC 17 ms
8,716 KB
testcase_09 AC 17 ms
8,880 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import sys

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

dp = [0] * (10**5 + 1)
def recurrence(n):
    if n==1:
        dp[n] = 1
    elif n==2:
        dp[n] = 2
    elif n==3:
        dp[n] = 6
    elif n==4:
        dp[n] = 28
    else:
        dp[n] = ( n*(dp[n-2]//(n-2) + dp[n-1]) ) % M
        '''
        for i in range(n-1, 0, -2):
            dp[n] += dp[i] % M
        dp[n] *= n
        dp[n] %= M
        '''
    return dp[n]

sys.setrecursionlimit(10**5+1)

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

print(dp[N])
0