ADS

Getting Started

  • Algorithms and Data Structures
  • Build and test
  • Use

User Guide

  • Layout
  • Where each thing comes from
  • Beyond the book
  • From The Art of Computer Programming
  • From Ferragina’s algorithm engineering
  • The exercises and the exams of the course
  • Engineered structures
  • Sorting
  • Design by contract
  • The standard interface
  • Further reading

API Reference

  • API Reference

Project

  • Release Notes
ADS
  • Program Listing for File DancingLinks.h
  • Edit on GitHub

Program Listing for File DancingLinks.h

↰ Return to documentation for file (ADS/backtrack/DancingLinks.h)

/*--------------------------------------------------------------------------*/
/*-------------------------- File DancingLinks.h ---------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef __ADS_DancingLinks
 #define __ADS_DancingLinks
                      /* self-identification: #endif constant */

/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/Contract.h"

#include <algorithm>
#include <cstddef>
#include <utility>
#include <vector>

/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/

namespace ADS {

/*--------------------------------------------------------------------------*/
/*--------------------------- CLASS ExactCover -----------------------------*/
/*--------------------------------------------------------------------------*/

class ExactCover {

/*--------------------------------------------------------------------------*/
 public:

 ExactCover( int primary , int secondary = 0 );

 int addOption( const std::vector< int > & items );

 template< class F >
 long solve( F && visit );

 [[nodiscard]] long updates( void ) const { return( f_updates ); }

/*--------------------------------------------------------------------------*/
 private:

 void cover( int i );
 void uncover( int i );
 void hide( int p );
 void unhide( int p );

 [[nodiscard]] bool exact( const std::vector< int > & options ) const;

 int f_primary , f_items;
 std::vector< int > f_L , f_R;
 std::vector< int > f_U , f_D , f_top;
 std::vector< int > f_len;
 std::vector< int > f_option;
 std::vector< std::vector< int > > f_options;
 long f_updates = 0;

 };  // end( class ExactCover )

/*--------------------------------------------------------------------------*/

}  // end( namespace ADS )

/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/backtrack/impl/DancingLinks.tpp"

/*--------------------------------------------------------------------------*/

#endif  /* DancingLinks.h included */

/*--------------------------------------------------------------------------*/
/*------------------------ End File DancingLinks.h -------------------------*/
/*--------------------------------------------------------------------------*/

© Copyright 2026, Donato Meoli.

Built with Sphinx using a theme provided by Read the Docs.