Duplicate dancing links overwrite Template

Source: Internet
Author: User

Duplicate dancing links overwrite Template


# Include <iostream> <br/> # include <cstdio> <br/> # include <string. h> <br/> # include <vector> <br/> # include <math. h> <br/> # define INF 0x3fffffff <br/> using namespace STD; <br/> const int n = 1005; <br/> const int M = 4000; <br/> int U [m], d [m], R [m], L [m], RS [N]; <br/> int size [N], head, row [m], Col [m]; <br/> int n, m, K; <br/> int nodecnt, ans; <br/> void Init (INT m) {<br/> memset (size, 0, sizeof (size); <br/> Memset (COL,-1, sizeof (COL); <br/> nodecnt = m + 1; <br/> for (INT I = 0; I <= m; I ++) {<br/> L [I] = (I-1); <br/> r [I] = (I + 1 ); <br/> Col [I] = I; <br/> d [I] = U [I] = I; <br/>}< br/> L [0] = m; <br/> r [m] = 0; <br/> size [0] = int_max; <br/>}< br/> inline void remove (int x) {<br/> for (INT I = d [X]; I! = X; I = d [I]) {<br/> L [R [I] = L [I]; <br/> r [L [I] = R [I]; <br/> size [col [I] --; <br/>}< br/> inline void resume (int x) {<br/> for (INT I = U [X]; I! = X; I = U [I]) {<br/> L [R [I] = R [L [I] = I; <br/> size [col [I] ++; <br/>}< br/> int rec [N]; <br/> inline int evalute () {/* valuation function */<br/> bool vis [40] = {false}; <br/> int TT = 0; <br/> for (INT I = R [0]; I! = 0; I = R [I]) <br/> If (! Vis [col [I]) {<br/> TT ++; <br/> vis [col [I] = true; <br/> for (Int J = d [I]; J! = I; j = d [J]) <br/> If (COL [J]! = 0) <br/> for (int K = R [J]; k! = J; k = R [k]) vis [col [k] = true; <br/>}< br/> return tt; <br/>}< br/> int DFS (INT num) {/* the DFS here is an iterative process */<br/> If (Num + evalute ()> ans) return 0; <br/> If (R [0] = 0) return 1; <br/> int I, j, opt = 0; <br/> for (I = R [0]; I! = 0; I = R [I]) <br/> If (size [col [I] <size [col [opt]) {<br/> opt = I; <br/> If (size [col [I] <= 1) break; <br/>}< br/> for (I = d [opt]; I! = OPT; I = d [I]) {<br/> remove (I); <br/> for (j = R [I]; I! = J; j = R [J]) Remove (j); <br/> If (DFS (Num + 1) return 1; <br/> for (j = L [I]; J! = I; j = L [J]) Resume (j); <br/> resume (I); <br/>}< br/> return 0; <br/>}< br/> inline void insert (int I, int * TT, int c) {<br/> for (Int J = 0; j <C; j ++, nodecnt ++) {<br/> int x = TT [J]; <br/> row [nodecnt] = I; <br/> Col [nodecnt] = x; <br/> size [x] ++; <br/> U [nodecnt] = X; <br/> d [nodecnt] = d [X]; <br/> U [d [x] = nodecnt; <br/> d [x] = nodecnt; <br/> If (j = 0) L [nodecnt] = R [nodecnt] = nodecnt; <Br/> else {<br/> L [nodecnt] = nodecnt-1; <br/> r [nodecnt] = nodecnt-J; <br/> r [nodecnt-1] = nodecnt; <br/> L [nodecnt-J] = nodecnt; <br/>}< br/> void build () {<br/>/* The graph creation process is precisely covered, insert (I, TT, c) */<br/>}< br/> void solve () {<br/> ans = 0; <br/> while (! DFS (0) {<br/> ans ++; <br/> If (ANS> m) break; <br/>}< br/>/* problem solving process */<br/>}< br/> int main () {<br/> while (scanf ("% d", & N, & M, & K )! = EOF) {<br/> Read ();/* read initialization */<br/> build ();/* graph creation process */<br/> solve (); /* problem solving process */<br/>}< br/> return 0; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.