AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC185-C Duodecim Ferra
C#のソース
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("12");
//1
}
else if (InputPattern == "Input2") {
WillReturn.Add("13");
//12
}
else if (InputPattern == "Input3") {
WillReturn.Add("17");
//4368
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long L = long.Parse(InputList[0]);
// 場合の数[分割数]なDP表
long[] PrevDP = new long[12];
PrevDP[0] = 1;
for (int I = 2; I <= L; I++) {
long[] CurrDP = (long[])PrevDP.Clone();
for (int J = 0; J <= 10; J++) {
if (PrevDP[J] == 0) continue;
CurrDP[J + 1] += PrevDP[J];
}
PrevDP = CurrDP;
}
Console.WriteLine(PrevDP[11]);
}
}
解説
動的計画法で解いてます。