結果
問題 |
No.65 回数の期待値の練習
|
ユーザー |
![]() |
提出日時 | 2015-09-12 11:27:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,963 ms / 5,000 ms |
コード長 | 2,418 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 108,160 KB |
実行使用メモリ | 232,852 KB |
最終ジャッジ日時 | 2024-07-19 06:15:55 |
合計ジャッジ時間 | 7,676 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List<string> GetInputList() { var WillReturn = new List<string>(); 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<string> InputList = GetInputList(); int K = int.Parse(InputList[0]); List<int[]> 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<int> NumList; } //合計がKになるまでの、サイコロの目の組み合わせを列挙 static List<int[]> ExecDFS(int pK) { var WillReturn = new List<int[]>(); var stk = new Stack<JyoutaiDef>(); JyoutaiDef WillPush; for (int I = 1; I <= 6; I++) { WillPush.NumList = new List<int>() { 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<int>(Popped.NumList) { I }; stk.Push(WillPush); } } return WillReturn; } }