結果

問題 No.336 門松列列
ユーザー btkbtk
提出日時 2016-01-16 02:57:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 144,896 KB
実行使用メモリ 33,700 KB
最終ジャッジ日時 2023-09-02 18:44:51
合計ジャッジ時間 2,090 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
30,528 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 35 ms
33,700 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 7 ms
14,192 KB
testcase_07 AC 15 ms
22,336 KB
testcase_08 AC 23 ms
28,476 KB
testcase_09 AC 32 ms
32,972 KB
testcase_10 AC 34 ms
33,512 KB
testcase_11 AC 34 ms
33,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD=1e9+7;

int N;
LL dp[2016][2016];
LL sum[2017];
LL getsum(int n,int p,int t){
    if(t)return (sum[n+1]-sum[p+1]+MOD)%MOD;
    else return (sum[p+1])%MOD;
}
LL f(int n,int t){
    if(n==N-1)fill(dp[N-1],dp[N-1]+N,1);
    if(n==0)return dp[0][0];
    sum[0]=0;
    for(int i = 0; i <= n; i++)sum[i+1]=(sum[i]+dp[n][i])%MOD;
    for(int i = 0; i < n; i++)dp[n-1][i]=getsum(n,i,t);
    return f(n-1,1-t);
}
int main() {
    cin>>N;
    if(N<=2)cout<<0<<endl;
    else cout<<(f(N-1,0)+f(N-1,1))%MOD<<endl;
    return 0;
}
0