The following code,

double[,] matrix = new double[,] { { 0.5, 0.25, 0.25 }, { 0.375, 0.125, 0.375 }, { 0.125, 0.675, 0.375 } };

System.Diagnostics.Debug.Assert(matrix.GetLength(0) == matrix.GetLength(1));

int sequences = 3;

for (int i = 0; i < (int)Math.Pow(matrix.GetLength(0), sequences); i++)

{

double p = 1;

Console.Write((char)('a' + ((i / (int)Math.Pow(matrix.GetLength(0), 0)) % matrix.GetLength(0))));

for (int j = 1; j < sequences; j++)

{

int a = (i / (int)Math.Pow(matrix.GetLength(0), j - 1)) % matrix.GetLength(0);

int b = (i / (int)Math.Pow(matrix.GetLength(0), j)) % matrix.GetLength(0);

p *= matrix[a, b];

Console.Write("->" + (char)('a' + b));

}

Console.WriteLine(" " + p);

}

Console.ReadLine();

produces the output ("a->a->b 0.125"),

a->a->a 0.25

b->a->a 0.1875

c->a->a 0.0625

a->b->a 0.09375

b->b->a 0.046875

c->b->a 0.253125

a->c->a 0.03125

b->c->a 0.046875

c->c->a 0.046875

a->a->b 0.125

b->a->b 0.09375

c->a->b 0.03125

a->b->b 0.03125

b->b->b 0.015625

c->b->b 0.084375

a->c->b 0.16875

b->c->b 0.253125

c->c->b 0.253125

a->a->c 0.125

b->a->c 0.09375

c->a->c 0.03125

a->b->c 0.09375

b->b->c 0.046875

c->b->c 0.253125

a->c->c 0.09375

b->c->c 0.140625

c->c->c 0.140625

double[,] matrix = new double[,] { { 0.5, 0.25, 0.25 }, { 0.375, 0.125, 0.375 }, { 0.125, 0.675, 0.375 } };

System.Diagnostics.Debug.A

int sequences = 3;

for (int i = 0; i < (int)Math.Pow(matrix.GetLe

{

double p = 1;

Console.Write((char)('a' + ((i / (int)Math.Pow(matrix.GetLe

for (int j = 1; j < sequences; j++)

{

int a = (i / (int)Math.Pow(matrix.GetLe

int b = (i / (int)Math.Pow(matrix.GetLe

p *= matrix[a, b];

Console.Write("->" + (char)('a' + b));

}

Console.WriteLine(" " + p);

}

Console.ReadLine();

produces the output ("a->a->b 0.125"),

a->a->a 0.25

b->a->a 0.1875

c->a->a 0.0625

a->b->a 0.09375

b->b->a 0.046875

c->b->a 0.253125

a->c->a 0.03125

b->c->a 0.046875

c->c->a 0.046875

a->a->b 0.125

b->a->b 0.09375

c->a->b 0.03125

a->b->b 0.03125

b->b->b 0.015625

c->b->b 0.084375

a->c->b 0.16875

b->c->b 0.253125

c->c->b 0.253125

a->a->c 0.125

b->a->c 0.09375

c->a->c 0.03125

a->b->c 0.09375

b->b->c 0.046875

c->b->c 0.253125

a->c->c 0.09375

b->c->c 0.140625

c->c->c 0.140625