結果
| 問題 | 
                            No.65 回数の期待値の練習
                             | 
                    
| コンテスト | |
| ユーザー | 
                             aketijyuuzou
                         | 
                    
| 提出日時 | 2024-10-10 22:27:55 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 38 ms / 5,000 ms | 
| コード長 | 2,470 bytes | 
| コンパイル時間 | 1,067 ms | 
| コンパイル使用メモリ | 109,184 KB | 
| 実行使用メモリ | 19,456 KB | 
| 最終ジャッジ日時 | 2024-10-10 22:27:58 | 
| 合計ジャッジ時間 | 2,485 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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 = "InputX";
    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;
    }
    //DP表の構造体
    struct DPInfoDef
    {
        internal int DiceCnt; //ダイスの数
        internal int SumNum;  //ダイスの目の和
        internal decimal Kakuritu; //状態遷移する確率
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        int K = int.Parse(InputList[0]);
        var DPInfoList = new List<DPInfoDef>();
        Action<int, int, decimal> MergeAct = (pDiceCnt, pSumNum, pKakuritu) =>
        {
            DPInfoDef WillMerge;
            WillMerge.DiceCnt = pDiceCnt;
            WillMerge.SumNum = pSumNum;
            WillMerge.Kakuritu = pKakuritu;
            //{DiceCnt,SumNum}をキーとして、確率の加法定理を使う
            int wkInd = DPInfoList.FindIndex(X => X.DiceCnt == pDiceCnt
                                               && X.SumNum == pSumNum);
            if (wkInd >= 0) {
                WillMerge.Kakuritu += DPInfoList[wkInd].Kakuritu;
                DPInfoList.RemoveAt(wkInd);
            }
            DPInfoList.Add(WillMerge);
        };
        //初期化
        MergeAct(0, 0, 1M);
        for (int I = 0; I <= DPInfoList.Count - 1; I++) {
            if (DPInfoList[I].SumNum >= K) continue;
            for (int Dice = 1; Dice <= 6; Dice++) {
                //確率の乗法定理でDP表を更新
                MergeAct(DPInfoList[I].DiceCnt + 1,
                         DPInfoList[I].SumNum + Dice,
                         DPInfoList[I].Kakuritu / 6M);
            }
        }
        DPInfoList.RemoveAll(X => X.SumNum < K);
        Console.WriteLine(DPInfoList.Sum(X => X.DiceCnt * X.Kakuritu));
    }
}
            
            
            
        
            
aketijyuuzou