結果

問題 No.45 回転寿司
ユーザー masakt
提出日時 2017-04-03 02:25:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 104,320 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-12-27 16:14:30
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class P
{
    static int Search(int i)
    {
        if (dp[i] > 0)
        {
            return dp[i];
        }
        int res = 0;
        if(i >= n)
        {
            res = 0;
        }
        else
        {
            res = Math.Max(Search(i + 2), Search(i + 3)) + V[i];
        }
        return dp[i] = res;
    }
    static int n;
    static int[] V = new int[1010];
    static int[] dp = new int[1010];

    static void Main(string[]_)
    {
        n = int.Parse(Console.ReadLine());
        _=Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            V[i] = int.Parse(_[i]);
        }
        Console.WriteLine(Math.Max(Search(0),Search(1)));
    }
}
0