using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("1"); //出力 //0.62191 //太郎君は普通のサイコロとイカサマなサイコロを1個づつ使用し、 //二郎君は普通のサイコロを2個使用します } else if (InputPattern == "Input2") { WillReturn.Add("10"); WillReturn.Add("0"); //出力 //0.47409 //太郎君はイカサマなサイコロを使わず、公平に勝負しました } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int N = int.Parse(InputList[0]); int K = int.Parse(InputList[1]); Dictionary CntDict1 = DeriveCntDict(N, K); Dictionary CntDict2 = DeriveCntDict(N, 0); //積の法則で分母を求める Decimal Bunbo = (Decimal)CntDict1.Values.Sum() * (Decimal)CntDict2.Values.Sum(); //積の法則で分子を求める Decimal Bunsi = 0; foreach (var EachPair1 in CntDict1) { foreach (var EachPair2 in CntDict2) { if (EachPair1.Key <= EachPair2.Key) continue; Bunsi += (Decimal)EachPair1.Value * (Decimal)EachPair2.Value; } } Console.WriteLine(Bunsi / Bunbo); } //合計ごとの場合の数を動的計画法で求める static Dictionary DeriveCntDict(int pN, int pK) { var PrevDP = new Dictionary(); PrevDP[0] = 1; //初期設定 for (int I = 1; I <= pN; I++) { var CurrDP = new Dictionary(); int[] DiceValsArr = { 1, 2, 3, 4, 5, 6 }; //456サイの場合 if (I <= pK) DiceValsArr = new int[] { 4, 5, 6, 4, 5, 6 }; foreach (int EachDiceVal in DiceValsArr) { foreach (var EachPair in PrevDP) { int NewKey = EachPair.Key + EachDiceVal; if (CurrDP.ContainsKey(NewKey)) { CurrDP[NewKey] += EachPair.Value; } else CurrDP[NewKey] = EachPair.Value; } } PrevDP = CurrDP; } return PrevDP; } }