很久以前用来枚举组合数的,当时应该是C(4,11)。
class Program
{
static void Main(string[] args)
{
int sum = 0;
int[] vs = new int[4];
int[] vars = new int[11]{1,2,3,4,5,6,7,8,9,10,11};
G(0, 0, 4, ref vars, ref vs, ref sum);
Console.WriteLine(sum);
}
static void G(int startIndex, int count, int n, ref int[] vars, ref int[] vs, ref int sum)
{
if (count == n)
{
sum++;
Console.WriteLine("{0}-{1}-{2}-{3}", vs[0], vs[1], vs[2], vs[3]);
}
else
{
if ((startIndex < vars.Length) && ((vars.Length - startIndex) >= (n - count)))
{
vs[count] = vars[startIndex];
count++;
G(startIndex + 1, count, n, ref vars, ref vs, ref sum);
count--;
G(startIndex + 1, count, n, ref vars, ref vs, ref sum);
}
}
}
}