Пример #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 numbers = Enumerable.Range(1, combinationLength).ToArray();

            SubsetsStrings.GenerateUniqueCombination(numbers, combinationLength, elementsCount);
        }
Пример #2
0
        private static void GenerateUniqueCombination(int[] range, int current, int count)
        {
            for (int i = 0; i < count; i++)
            {
                if (current > 1)
                {
                    SubsetsStrings.GenerateUniqueCombination(range, current - 1, count);
                }
                else
                {
                    if (!SubsetsStrings.HasDuplicateElements(range))
                    {
                        SubsetsStrings.PrintElements(range);
                    }
                }

                SubsetsStrings.IncrementWithoutDuplicates(range, range.Length - current);
                if (!SubsetsStrings.ValueIsInRange(range, range.Length - current, count))
                {
                    range[range.Length - current]--;
                    break;
                }
            }
        }