using System; using System.Collections.Generic; //http://yukicoder.me/problems/no/220 //No.220 世界のなんとか2 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("1"); //3 } else if (InputPattern == "Input2") { WillReturn.Add("2"); //45 } else if (InputPattern == "Input3") { WillReturn.Add("19"); //9099432188218005273 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int P = int.Parse(InputList[0]); //場合の数[3を法とした余り,3の有無]なDP表 long[,] PrevDP = new long[3, 2]; PrevDP[0, 0] = 1; for (int I = 1; I <= P; I++) { long[,] CurrDP = new long[3, 2]; for (int J = 0; J <= PrevDP.GetUpperBound(0); J++) { for (int K = 0; K <= PrevDP.GetUpperBound(1); K++) { if (PrevDP[J, K] == 0) continue; for (int NewNum = 0; NewNum <= 9; NewNum++) { int NewJ = (J + NewNum) % 3; int NewK = K; if (NewNum == 3) NewK = 1; CurrDP[NewJ, NewK] += PrevDP[J, K]; } } } PrevDP = CurrDP; } long Answer = 0; for (int I = 0; I <= PrevDP.GetUpperBound(0); I++) { for (int J = 0; J <= PrevDP.GetUpperBound(1); J++) { if (I == 0 || J == 1) Answer += PrevDP[I, J]; } } Answer--; //0の分 Console.WriteLine(Answer); } }