int lbs(int array[], int n) { int maximumLbsLength = INT_MIN, lbsArrayIterator; int* lisArray = lis (array, n); int* ldsArray = lds (array, n); for(lbsArrayIterator = 0; lbsArrayIterator < n ; lbsArrayIterator++) { if ((lisArray[lbsArrayIterator] + ldsArray[lbsArrayIterator] - 1) > maximumLbsLength) { maximumLbsLength = lisArray[lbsArrayIterator] + ldsArray[lbsArrayIterator] - 1; } } free(lisArray); free(ldsArray); return maximumLbsLength; }
bool Main::runLDS() { #ifdef PARALLEL_STATIC if (m_options->par_postOnly) return true; // skip LDS for static post mode #endif // Run LDS if specified if (m_options->lds != NONE) { cout << "Running LDS with limit " << m_options->lds << endl; scoped_ptr<SearchSpace> spaceLDS(new SearchSpace(m_pseudotree.get(), m_options.get())); LimitedDiscrepancy lds(m_problem.get(), m_pseudotree.get(), spaceLDS.get(), m_heuristic.get(), m_options->lds); if (!m_options->in_subproblemFile.empty()) { if (!lds.restrictSubproblem(m_options->in_subproblemFile)) { err_txt("Subproblem restriction for LDS failed."); return false; } } // load current best solution into LDS if (lds.updateSolution(m_problem->getSolutionCost() #ifndef NO_ASSIGNMENT , m_problem->getSolutionAssg() #endif )) cout << "LDS: Initial solution loaded." << endl; BoundPropagator propLDS(m_problem.get(), spaceLDS.get(), false); // doCaching = false lds.finalizeHeuristic(); SearchNode* n = lds.nextLeaf(); while (n) { propLDS.propagate(n,true); // true = report solution n = lds.nextLeaf(); } cout << "LDS: explored " << spaceLDS->stats.numExpOR << '/' << spaceLDS->stats.numExpAND << " OR/AND nodes" << endl; cout << "LDS: solution cost " << lds.getCurOptValue() << endl; #ifndef NO_HEURISTIC if (m_search->getCurOptValue() >= m_heuristic->getGlobalUB()) { m_solved = true; cout << endl << "--------- Solved by LDS ---------" << endl; } #endif } return true; }
main(i,n){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",x+i);lds(n);}