結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2024-10-10 21:44:58 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 2,913 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 115,884 KB |
実行使用メモリ | 29,928 KB |
最終ジャッジ日時 | 2024-10-10 21:45:01 |
合計ジャッジ時間 | 3,582 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("4"); WillReturn.Add("1 2 3 4"); //6 //お寿司の取り方は、 //「1個目と3個目」のお寿司を取る、 //「1個目と4個目」のお寿司を取る、 //または「2個目と4個目」のお寿司を取る方法があるが、 //2個目、4個目のお寿司を取ることで、最大の美味しさが得られる。 } else if (InputPattern == "Input2") { WillReturn.Add("4"); WillReturn.Add("5 4 4 9"); //14 //1個目のお寿司と4個目のお寿司を取ることで //最大の美味しさの合計が得られる。 } else if (InputPattern == "Input3") { WillReturn.Add("7"); WillReturn.Add("1 2 9 10 1 1 4"); //2,10,4と取れば最大の16が得られる。 //10の後の6番目の1をあえてスルーしないといけない。 } else if (InputPattern == "Input4") { WillReturn.Add("1"); WillReturn.Add("100"); //100 //1皿しかない場合もあります。 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] VArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray(); int UB = VArr.GetUpperBound(0); //美味しさ合計の最大値[皿の合計]のDP表 int[] DPArr = new int[UB + 1]; for (int I = 0; I <= UB; I++) { if (I == 0 || I == 1) { DPArr[I] = VArr[I]; continue; } //配列の添字の上限までの範囲での、最大値を返す Func<int, int> DeriveHaniMaxFunc = pJyougenInd => { int WillReturn = DPArr[0]; for (int J = 0; J <= pJyougenInd; J++) { if (WillReturn < DPArr[J]) WillReturn = DPArr[J]; } return WillReturn; }; //その皿を取るノードでの美味しさ合計の最大値 int Node1SumV = DeriveHaniMaxFunc(I - 2) + VArr[I]; //その皿を取らないノードでの美味しさ合計の最大値 int Node2SumV = DeriveHaniMaxFunc(I - 1); DPArr[I] = Math.Max(Node1SumV, Node2SumV); } Console.WriteLine(DPArr.Max()); } }