示例#1
0
        public static void Main()
        {
            var elementsCount     = int.Parse(Console.ReadLine());
            var combinationLength = int.Parse(Console.ReadLine());

            elementsToDisplay = Enumerable.Range(0, elementsCount).Select(x => Console.ReadLine()).ToArray();
            var range = Enumerable.Range(0, combinationLength).Select(x => 1).ToArray();

            Subsets.GenerateCombination(range, combinationLength, elementsCount);
        }
示例#2
0
        private static void GenerateCombination(int[] range, int current, int count)
        {
            for (int i = 0; i < count; i++)
            {
                if (current > 1)
                {
                    Subsets.GenerateCombination(range, current - 1, count);
                }
                else
                {
                    Subsets.PrintElements(range);
                }

                range[range.Length - current]++;
            }

            range[range.Length - current] = 1;
        }