思路是用递归把所有可能性都计算出来,放在一个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);