HDU 3663 Dance chain's non-repeatable coverage

Source: Internet
Author: User

Click to open link

Test instructions: Give a graph, and then n the power supply range of the city, each now requires each city's D day can have electricity, for city a power, then all the cities adjacent to it will have electricity, but the problem is that each city can only be powered once a day, otherwise it will be broken, And each city has a range of days of power supply and each city can only open the switch once, and can not be used, that is, city A's power supply time must be continuous, there is no need for this city

Idea: Because each city can only be powered once a day, then is not repeated coverage of the dance chain model, then consider what as columns and rows, it is obvious that the problem is n*d+n as a column, N*d is N city D days are to power, and then the next n is to ensure that each city direct power generation, And then consider what as the line, for a city's power generation range, we can intercept all the small areas to be used as rows, of course, not the case to add a 0 0, such as 1 to 5 of the range can become 16 rows, 0 0,1 2,1 3,1 4,1 5,2 2,2 3,2 4,2 5,3 3,3 4, 3 5,4 5,5 5, for each range they even the column is their corresponding number of days of the city, is some small details of the treatment, roughly this is the case, to do not forget the heavy side, heavy edge, heavy side, the main thing said three times

#include <vector> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < Iostream> #include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;const int in f=0x3f3f3f3f;const ll Inf=0x3f3f3f3f3f3f3f3fll;const int Maxn=1010;int l[maxn*400],r[maxn*400],u[maxn*400],d[maxn* 400];//node up and down four-way linked list int c[maxn*400],h[maxn],cnt[maxn],ans[maxn],row[maxn*400];//c column H row cnt list element number int n,m,id,len,d    ; vector<int>g[maxn];void init (int lll) {for (int i=0;i<maxn;i++) g[i].clear (); for (int i=0;i<=lll;i++) {cnt[i]=0;        U[i]=d[i]=i; L[i+1]=i;    r[i]=i+1;    } r[lll]=0;id=lll+1; memset (h,-1,sizeof (H)); void Link (int r,int c) {cnt[c]++; C[id]=c;    Row[id]=r;    U[ID]=U[C];D [U[c]]=id; D[id]=c;    U[c]=id;    if (h[r]==-1) H[r]=l[id]=r[id]=id; else{L[id]=l[h[r]];        R[l[h[r]]]=id; R[ID]=H[R];    L[h[r]]=id; } id++;}    void Remove (int Size) {l[r[size]]=l[size];    R[l[size]]=r[size]; for (int i=d[sIze];i!=size;i=d[i] {for (int j=r[i];j!=i;j=r[j]) {u[d[j]]=u[j];D [u[j]]=d[j];        cnt[c[j]]--; }}}void Resume (int Size) {for (Int. I=d[size];i!=size;i=d[i]) {for (int j=r[i];j!=i;j=r[j]) {U[d[j]]            =j;d[u[j]]=j;        cnt[c[j]]++; }} l[r[size]]=size; R[l[size]]=size;}     int Dance (int k) {int c; if (!         R[0]) {len=k;     return 1;     } for (int min=inf,i=r[0];i;i=r[i]) if (min>cnt[i]) min=cnt[i],c=i;     Remove (c);         for (int i=d[c];i!=c;i=d[i]) {ans[k]=row[i];         for (int j=r[i];j!=i;j=r[j]) Remove (C[j]);         if (Dance (k+1)) return 1;    for (int j=l[i];j!=i;j=l[j]) Resume (C[j]);    } Resume (c); return 0;}    int a[70],b[70],tmp[maxn][2];void linkline (int l,int r,int x,int KKK) {Link (kkk,n*d+x);        for (int i=l;i<=r;i++) {Link (KKK, (i-1) *n+x);            for (unsigned j=0;j<g[x].size (); j + +) {int t=g[x][j];        Link (KKK, (i-1) *n+t);    }}}int Visedge[70][70];int Main () {int u,v;        while (scanf ("%d%d%d", &n,&m,&d)!=-1) {init (n*d+n);        memset (visedge,0,sizeof (Visedge));            for (int i=1;i<=m;i++) {scanf ("%d%d", &u,&v);            if (Visedge[u][v]) continue;            G[u].push_back (v);            G[v].push_back (U);        Visedge[u][v]=1;visedge[v][u]=1;        } for (int i=1;i<=n;i++) scanf ("%d%d", &a[i],&b[i]);        int kkk=1;            for (int i=1;i<=n;i++) {tmp[kkk][0]=0;tmp[kkk++][1]=0;            Link (Kkk-1,n*d+i); for (int j=a[i];j<=b[i];j++) {for (int l=j;l<=b[i];l++) {tmp[kkk][0]=j;tmp[kkk++][1]                    =l;                Linkline (j,l,i,kkk-1);        }}} int flag=dance (0);        if (flag==0) printf ("No solution\n");            else{sort (Ans,ans+len);        for (int i=0;i<len;i++) printf ("%d%d\n", tmp[ans[i]][0],tmp[ans[i]][1]); }        printf ("\ n"); } return 0;}

HDU 3663 Dance chain's non-repeatable coverage

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.