AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC178-D Redistribution
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("7");
//3
}
else if (InputPattern == "Input2") {
WillReturn.Add("2");
//0
}
else if (InputPattern == "Input3") {
WillReturn.Add("1729");
//294867501
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int S = int.Parse(InputList[0]);
const int Hou = 1000000000 + 7;
//場合の数[和]なDP表
int UB = S;
int[] DPArr = new int[UB + 1];
DPArr[0] = 1;
for (int I = 0; I <= UB; I++) {
if (DPArr[I] == 0) continue;
for (int J = 3; J <= S; J++) {
int NewInd = I + J;
if (UB < NewInd) break;
DPArr[NewInd] += DPArr[I];
DPArr[NewInd] %= Hou;
}
}
Console.WriteLine(DPArr[UB]);
}
}
解説
動的計画法で解いてます。