std::pair<bool, std::vector<int>> DancingLink(int n, int m, int s[MAX][MAX]) { BuildLink(s, n, m); DumpGraph(s, n, m); bool dance = Dance(1, s, n, m); std::vector<int> vec; std::transform(chose, chose + n + 1, std::back_inserter(vec), [](const int &v) { return v; }); return std::make_pair(dance, vec); }
static bool Dance(int x, int s[MAX][MAX], int n, int m) { //头节点一行的所有元素都被删除 //只剩0节点 if (leftlink[0] == 0) { return true; } //已经被子集覆盖 //不再重复操作 if (cover[collink[x]]) { return Dance(x + 1, s, n, m); } Remove(index(0, x, m)); DumpGraph(s, n, m); //遍历所有包含x的子集 for (int p = downlink[index(0, x, m)]; p != index(0, x, m); p = downlink[p]) { //选择子集rowlink[p] chose[rowlink[p]] = 1; //删除包含子集rowlink[p]所有元素的子集 for (int q = rightlink[p]; q != p; q = rightlink[q]) Remove(index(0, collink[q], m)); DumpGraph(s, n, m); //下一个元素x+1 if (Dance(x + 1, s, n, m)) return true; //排除子集rowlink[p] chose[rowlink[p]] = 0; //恢复链表 for (int q = leftlink[p]; q != p; q = leftlink[q]) Resume(index(0, collink[q], m)); DumpGraph(s, n, m); } Resume(index(0, x, m)); DumpGraph(s, n, m); return false; }
int main(int argc,char **argv) { if (argc!=2) { printf("Usage: %s xmldir\n",argv[0]); exit(1); } IDoxygen *dox = createObjectModel(); dox->setDebugLevel(4); if (!dox->readXMLDir(argv[1])) { printf("Error reading %s/index.xml\n",argv[1]); exit(1); } ICompoundIterator *cli = dox->compounds(); ICompound *comp; printf("--- compound list ---------\n"); for (cli->toFirst();(comp=cli->current());cli->toNext()) { printf("Compound name=%s id=%s kind=%s\n", comp->name()->latin1(),comp->id()->latin1(),comp->kindString()->latin1()); ISectionIterator *sli = comp->sections(); ISection *sec; for (sli->toFirst();(sec=sli->current());sli->toNext()) { printf(" Section kind=%s\n",sec->kindString()->latin1()); IMemberIterator *mli = sec->members(); IMember *mem; if( sec->kind() == ISection::UserDefined ) { IUserDefined *group = dynamic_cast<IUserDefined*>(sec); printf(" Title=%s\n", group->header()->latin1() ); } for (mli->toFirst();(mem=mli->current());mli->toNext()) { ILinkedTextIterator *lti = mem->type(); printf(" Member type=%s name=%s\n", linkedTextToString(lti).latin1(),mem->name()->latin1()); lti->release(); IParamIterator *pli = mem->parameters(); DumpParamList(pli,6); pli->release(); IMemberReferenceIterator *mri = mem->references(); IMemberReference *mr; for (mri->toFirst();(mr=mri->current());mri->toNext()) { IMember *memr = mr->member(); printf(" References %s at line %d\n", mr->name()->latin1(),memr->bodyStart()); } mri->release(); mri = mem->referencedBy(); for (mri->toFirst();(mr=mri->current());mri->toNext()) { IMember *memr = mr->member(); printf(" ReferencedBy %s at line %d\n", mr->name()->latin1(),memr->bodyStart()); } mri->release(); if (mem->kind()==IMember::Enum) // we have found an enum { IEnum *e = dynamic_cast<IEnum*>(mem); IMemberIterator *evi = e->enumValues(); // get the enum values IMember *mev; for (evi->toFirst();(mev=evi->current());evi->toNext()) { IEnumValue *ev = dynamic_cast<IEnumValue*>(mev); ILinkedTextIterator *lti = ev->initializer(); QString init = linkedTextToString(lti); lti->release(); printf(" Enum value `%s' init=`%s'\n", ev->name()->latin1(),init.latin1()); } evi->release(); } pli = mem->templateParameters(); if (pli) { printf(" Template parameters\n"); DumpParamList(pli,8); pli->release(); } IDoc *doc = mem->briefDescription(); if (doc) { printf("===== brief description ==== \n"); DumpDoc(doc,0); } doc = mem->detailedDescription(); if (doc) { printf("===== detailed description ==== \n"); DumpDoc(doc,0); } } mli->release(); } sli->release(); IDoc *doc = comp->briefDescription(); if (doc) { printf("===== brief description ==== \n"); DumpDoc(doc,0); } doc = comp->detailedDescription(); if (doc) { printf("===== detailed description ==== \n"); DumpDoc(doc,0); } if (comp->kind()==ICompound::Class) { IClass *cls = dynamic_cast<IClass*>(comp); ASSERT(cls!=0); printf("==== inheritance graph ==== \n"); DumpGraph(cls->inheritanceGraph()); printf("==== collabration graph ==== \n"); DumpGraph(cls->collaborationGraph()); printf("==== base classes ==== \n"); IRelatedCompoundIterator *bcli = cls->baseCompounds(); IRelatedCompound *bClass; for (bcli->toFirst();(bClass=bcli->current());bcli->toNext()) { ICompound *bc = bClass->compound(); printf(" + class %s\n",bc->name()->latin1()); bc->release(); } bcli->release(); printf("==== derived classes ==== \n"); IRelatedCompoundIterator *dcli = cls->derivedCompounds(); IRelatedCompound *dClass; for (dcli->toFirst();(dClass=dcli->current());dcli->toNext()) { ICompound *dc = dClass->compound(); printf(" + class %s\n",dc->name()->latin1()); dc->release(); } dcli->release(); } else if (comp->kind()==ICompound::File) { IFile *file = dynamic_cast<IFile*>(comp); ASSERT(file!=0); printf("==== include dependency graph ==== \n"); DumpGraph(file->includeDependencyGraph()); printf("==== included by dependency graph ==== \n"); DumpGraph(file->includedByDependencyGraph()); printf("==== source ====\n"); DumpDoc(file->source(),0); } comp->release(); } cli->release(); printf("---------------------------\n"); dox->release(); return 0; }