Exemple #1
0
        public IEnumerable <IEnumerable <T> > Backtrack(int[] vector, int k, IEnumerable <T> set)
        {
            var list = new List <IEnumerable <T> >();

            if (_solution.IsSolution(vector, k, set))
            {
                list.Add(_solution.GetSolution(vector, k, set));
            }
            else
            {
                k += 1;

                var candidates = _solution.ConstructCandidates(vector, k, set);

                foreach (var bit in candidates)
                {
                    vector[k] = bit;

                    _solution.MakeMove(vector, k, set);

                    list.AddRange(Backtrack(vector, k, set));

                    _solution.UnmakeMove(vector, k, set);
                }
            }

            return(list);
        }