N个筛子,掷出M值的可能性
来源:互联网 发布:小型图书馆源码 编辑:程序博客网 时间:2024/04/20 21:18
思路是用递归把所有可能性都计算出来,放在一个Dictionary里面。
using System.Collections.Generic;using System.Linq;using NUnit.Framework;namespace ClassLibrary{ [TestFixture] public class GambleTest { [Test] public void GambleTestEntrance() { var instance = new Gamble(); int n = 3; instance.CaculatePossibility(0, n); Dictionary<int, int> result = instance.possibleDict; } public class Gamble { private int maxSides = 6; public Dictionary<int, int> possibleDict = new Dictionary<int, int>(); public void CaculatePossibility(int currentSum, int n) { for (int i = 1; i <= maxSides; i++) { if (n == 1) { putIntoDict(currentSum + i); } else { CaculatePossibility(currentSum + i, n - 1); } } } private void putIntoDict(int currentSum) { if (possibleDict.Keys.Contains(currentSum)) { possibleDict[currentSum]++; } else { possibleDict[currentSum] = 1; } } } }}
- N个筛子,掷出M值的可能性
- n个筛子的点数
- 22 k个骰子掷出n的概率
- 43 n 个筛子 的点数
- 面试题数据结构-n个筛子的点数
- 每日一题(70) - n个筛子的点数
- 剑指offer面试题43:n个筛子的点数
- 剑指offer43-计算n个色子掷出各个点数和的概率
- n个人有n个帽子,每个人都不带自己帽子的可能性
- 生成n以内的m个随机数
- 产生m个n以内的随机数
- n个元素入栈顺序一定时,出栈顺序的可能性数量
- rand-取小于一个定值M以内,N个不重复的数(M>=N)
- AspNetPager不显示的N种可能性
- AspNetPager不显示的N种可能性
- AspNetPager不显示的N种可能性
- AspNetPager不显示的N种可能性
- 将m个苹果放入n个盘子的问题
- Ajax长连接
- Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton
- HDU_4701_Game
- 实现FusionChart动态获取数据(二)
- 关系模型的基本概念
- N个筛子,掷出M值的可能性
- 2013.8.25
- wikioi p1166 矩阵取数游戏
- 烟台大学acm暑期集训总结
- 谷歌笔试题-背包问题
- POJ 1637 - Sightseeing tour 判断混合图是否是欧拉回路(最大流)
- Hibernate 4 Util
- 重载_static_new
- wikioi p1010 过河卒