結果
問題 | No.58 イカサマなサイコロ |
ユーザー |
![]() |
提出日時 | 2024-10-10 22:06:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 2,794 bytes |
コンパイル時間 | 1,037 ms |
コンパイル使用メモリ | 114,144 KB |
実行使用メモリ | 27,572 KB |
最終ジャッジ日時 | 2024-10-10 22:06:25 |
合計ジャッジ時間 | 2,371 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
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 = "InputX";static List<string> GetInputList(){var WillReturn = new List<string>();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<string> InputList = GetInputList();int N = int.Parse(InputList[0]);int K = int.Parse(InputList[1]);Dictionary<int, int> CntDict1 = DeriveCntDict(N, K);Dictionary<int, int> 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<int, int> DeriveCntDict(int pN, int pK){var PrevDP = new Dictionary<int, int>();PrevDP[0] = 1; //初期設定for (int I = 1; I <= pN; I++) {var CurrDP = new Dictionary<int, int>();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;}}