예제 #1
0
        private static void CollectSets(FastList <int> packages, int target, List <int> group, List <int[]> collection)
        {
            FastList <int> workingSet = new(packages);

            packages.ForEach(package =>
            {
                workingSet = workingSet.Without(package);

                group.Add(package);

                int sum = Sum(group);
                if (sum == target)
                {
                    collection.Add(group.ToArray());
                }
                else if (sum < target)
                {
                    CollectSets(workingSet, target, group, collection);
                }

                group.Remove(package);
            });
        }