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"); //6 //サイコロを6回は振らないとちょうど1は出ないとみなせる。 } else if (InputPattern == "Input2") { WillReturn.Add("2"); //6 //1/6の確率で2を出す試行と考えれば6回も振ればちょうど2になるとみなせる。 //もし最初に1が出てしまったとしても、 //次に1/6の確率で1を出せばよいだけなので状況はなんら変わりない。 } else if (InputPattern == "Input3") { WillReturn.Add("3"); //6 } else if (InputPattern == "Input4") { WillReturn.Add("7"); //9.94315 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } //確率の下限 const decimal KakurituKagen = 0.000000001M; static void Main() { List InputList = GetInputList(); int K = int.Parse(InputList[0]); //状態遷移する確率[ダイスの目の和]なDP表 decimal[] PrevDP = new decimal[K]; PrevDP[0] = 1M; decimal Kitaiti = 0M; for (int DiceCnt = 1; ; DiceCnt++) { if (Array.TrueForAll(PrevDP, X => X < KakurituKagen)) break; decimal[] CurrDP = new decimal[K]; for (int I = 0; I <= PrevDP.GetUpperBound(0); I++) { if (PrevDP[I] == 0M) continue; for (int DiceNum = 1; DiceNum <= 6; DiceNum++) { int NewInd = I + DiceNum; if (NewInd == K) { Kitaiti += DiceCnt * PrevDP[I] / 6M; } else { if (NewInd > K) NewInd = 0; //確率の乗法定理と加法定理でDP表を更新 CurrDP[NewInd] += PrevDP[I] / 6M; } } } PrevDP = CurrDP; } Console.WriteLine(Kitaiti); } }