結果

問題 No.533 Mysterious Stairs
ユーザー hogeki
提出日時 2017-07-22 23:19:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 1,289 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 109,168 KB
実行使用メモリ 54,248 KB
最終ジャッジ日時 2024-10-09 10:03:52
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem533
{
    class Program
    {
        const long M = 1000000007;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if(N == 1 || N == 2)
            {
                Console.WriteLine(1);
                return;
            }
            else if(N == 3)
            {
                Console.WriteLine(3);
                return;
            }
            
            long[,] dp = new long[N + 1, 4];

            dp[1, 1] = 1;
            dp[2, 2] = 1;
            dp[3, 3] = 1;
            dp[3, 2] = 1;
            dp[3, 1] = 1;

            for(int i = 4; i <= N; i++)
            {
                dp[i, 1] = (dp[i - 1, 2] + dp[i - 1, 3]) % M;
                //Console.WriteLine("dp[{0},1] = {1}", i, dp[i, 1]);
                dp[i, 2] = (dp[i - 2, 1] + dp[i - 2, 3]) % M;
                //Console.WriteLine("dp[{0},2] = {1}", i, dp[i, 2]);

                dp[i, 3] = (dp[i - 3, 1] + dp[i - 3, 2]) % M;
                //Console.WriteLine("dp[{0},3] = {1}", i, dp[i, 3]);

            }

            Console.WriteLine(((dp[N,1] + dp[N, 2]) % M + dp[N,3]) % M);

        }
    }
}
0