using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("1"); //1 } else if (InputPattern == "Input2") { WillReturn.Add("2"); //1.16667 } else if (InputPattern == "Input3") { WillReturn.Add("3"); //1.36111 } else if (InputPattern == "Input4") { WillReturn.Add("7"); //2.52163 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int K = int.Parse(InputList[0]); List NumList = ExecDFS(K); decimal Kitaiti = 0; foreach (int[] EachArr in NumList) { decimal Bunbo = 1; for (int I = 1; I <= EachArr.Length; I++) Bunbo *= 6; decimal Bunsi = 1; Kitaiti += EachArr.Length * Bunsi / Bunbo; } Console.WriteLine(Kitaiti); } //階乗を求める static decimal DeriveKaijyou(int pN) { decimal WillReturn = 1; for (int I = 2; I <= pN; I++) { WillReturn *= I; } return WillReturn; } struct JyoutaiDef { internal List NumList; } //合計がKになるまでの、サイコロの目の組み合わせを列挙 static List ExecDFS(int pK) { var WillReturn = new List(); var stk = new Stack(); JyoutaiDef WillPush; for (int I = 1; I <= 6; I++) { WillPush.NumList = new List() { I }; stk.Push(WillPush); } while (stk.Count > 0) { JyoutaiDef Popped = stk.Pop(); //クリア判定 if (Popped.NumList.Sum() >= pK) { WillReturn.Add(Popped.NumList.ToArray()); continue; } for (int I = 1; I <= 6; I++) { WillPush.NumList = new List(Popped.NumList) { I }; stk.Push(WillPush); } } return WillReturn; } }