学习资料: http://www.cnblogs.com/grenet/p/3145800.html

http://blog.csdn.net/mu399/article/details/7627862

2份模版 第一份精确覆盖 from POJ 3074

const int N = ;
const int MAXN = N * N * N + ;
const int MAXM = N * N * + ;
const int MAXNODE = MAXN * + MAXM + ;
int g[MAXN];
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ; i <= m ; i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i - ;
R[i] = i + ;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++) H[i] = -;
} void link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c] ; i != c ; i = D[i])
for(int j = R[i] ; j != i ; j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
for(int j = L[i] ; j != i ; j = L[j])
++S[Col[U[D[j]] = D[U[j]] = j]];
L[R[c]] = R[L[c]] = c;
} bool Dance(int d)
{
if(R[] == )
{
for(int i = ;i < d ; i++)g[(ans[i] - ) / N] = (ans[i] - ) % + ;
for(int i = ;i < N * N ; i++)
{
printf("%d",g[i]);
// if (i % N == N - 1) putchar('\n');
}
return true;
}
int c = R[];
for(int i = R[] ; i != ; i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c] ; i != c ; i = D[i])
{
ans[d] = Row[i];
for(int j = R[i] ; j != i ; j = R[j]) Remove(Col[j]);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j]) resume(Col[j]);
}
resume(c);
return false;
}
};

第二份重复覆盖 from HDU 2295

struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ands,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++)
H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = ;
for(int c = R[] ; c != ; c = R[c])v[c] = true;
for(int c = R[] ; c != ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} bool Dance(int d)
{
if(d + f() > K)return false;
if(R[] == )return d <= K;
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return false;
}
};

HUST 1017 Exact cover

裸题

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int INF = 0x3f3f3f3f;
const int MAXN = ;
const int MAXM = ;
const int MAXNODE = MAXN * MAXN;
int g[MAXN];
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ; i <= m ; i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i - ;
R[i] = i + ;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++) H[i] = -;
} void link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c] ; i != c ; i = D[i])
for(int j = R[i] ; j != i ; j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
for(int j = L[i] ; j != i ; j = L[j])
++S[Col[U[D[j]] = D[U[j]] = j]];
L[R[c]] = R[L[c]] = c;
} bool Dance(int d)
{
if(R[] == )
{
printf("%d ",d);
for (int i = ; i < d ; i++)
printf("%d%c",ans[i],i == d - ? '\n' : ' ');
return true;
}
int c = R[];
for(int i = R[] ; i != ; i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c] ; i != c ; i = D[i])
{
ans[d] = Row[i];
for(int j = R[i] ; j != i ; j = R[j]) Remove(Col[j]);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j]) resume(Col[j]);
}
resume(c);
return false;
}
}; DLX slover;
int N,M; int main()
{
//freopen("sample.txt","r",stdin);
while (scanf("%d%d",&N,&M) != EOF)
{
slover.init(N,M);
for (int i = ; i <= N ; i++)
{
int cnt;
scanf("%d",&cnt);
while(cnt--)
{
int x;
scanf("%d",&x);
slover.link(i,x);
}
}
if (!slover.Dance()) puts("NO");
putchar('\n');
}
return ;
}

ZOJ 3209 Treasure Map

每个矩形为行,对应的可以包含的为列

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int INF = 0x3f3f3f3f;
const int MAXN = ;
const int MAXM = ;
const int MAXNODE = MAXN * MAXM;
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ; i <= m ; i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i - ;
R[i] = i + ;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++) H[i] = -;
} void link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c] ; i != c ; i = D[i])
for(int j = R[i] ; j != i ; j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
for(int j = L[i] ; j != i ; j = L[j])
++S[Col[U[D[j]] = D[U[j]] = j]];
L[R[c]] = R[L[c]] = c;
} void Dance(int d)
{
if(ansd != - && d > ansd) return;
if(R[] == )
{
if (ansd == -) ansd = d;
else ansd = min(ansd,d);
return;
}
int c = R[];
for(int i = R[] ; i != ; i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c] ; i != c ; i = D[i])
{
ans[d] = Row[i];
for(int j = R[i] ; j != i ; j = R[j]) Remove(Col[j]);
Dance(d + );
for(int j = L[i] ; j != i ; j = L[j]) resume(Col[j]);
}
resume(c);
return;
}
}; DLX slover;
int N,M,Q; int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&N,&M,&Q);
slover.init(Q,N * M);
for (int i = ; i <= Q ; i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
for (int j = x1 + ; j <= x2 ; j++)
for (int k = y1 + ; k <= y2 ; k++)
{
int pos = (j - ) * M + k;
slover.link(i,pos);
}
}
slover.ansd = -;
slover.Dance();
printf("%d\n",slover.ansd);
}
return ;
}

HDU 2295 Radar

二分+DLX

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
const int MAXNODE = MAXN * MAXM;
const double eps = 1e-;
int K;
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ands,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++)
H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = ;
for(int c = R[] ; c != ; c = R[c])v[c] = true;
for(int c = R[] ; c != ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} bool Dance(int d)
{
if(d + f() > K)return false;
if(R[] == )return d <= K;
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return false;
}
}; DLX slover;
struct point
{
int x,y;
}city[MAXN],station[MAXN]; inline double dis(point a,point b)
{
return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
} int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int n,m;
scanf("%d%d%d",&n,&m,&K);
for (int i = ; i < n ; i++)scanf("%d%d",&city[i].x,&city[i].y);
for (int i = ; i < m ; i++)scanf("%d%d",&station[i].x,&station[i].y);
double l = ,r = 1e8;
while (r - l > eps)
{
double mid = l + (r - l) / ;
slover.init(m,n);
for (int i = ; i < m ; i++)
{
for (int j = ; j < n ; j++)
{
double dist = dis(station[i],city[j]);
if (dist < mid - eps)
slover.Link(i + ,j + );
}
}
if (slover.Dance()) r = mid - eps;
else l = mid + eps;
}
printf("%.6lf\n",l);
}
return ;
}

FZU 1686 神龙的难题

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = ;
const int MAXNODE = MAXN * MAXN;
const int INF = 0x3f3f3f3f; struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++)
H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = ;
for(int c = R[] ; c != ; c = R[c])v[c] = true;
for(int c = R[] ; c != ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} void Dance(int d)
{
if(d + f() >= ansd)return;
if(R[] == )
{
ansd = min(ansd,d);
return;
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
Dance(d + );
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return;
}
}; int id[][];
int N,M;
int ln,lm;
DLX slover; int main()
{
while (scanf("%d%d",&N,&M) != EOF)
{
int cas = ;
memset(id,,sizeof(id));
for (int i = ; i <= N ; i++)
{
for (int j = ; j <= M ; j++)
{
int x;
scanf("%d",&x);
if (x) id[i][j] = ++cas;
}
}
scanf("%d%d",&ln,&lm);
slover.init(N * M,cas);
cas = ;
for (int i = ; i <= N ; i++)
{
for (int j = ; j <= M ; j++)
{
for (int stepx = ; stepx < ln && i + stepx <= N ; stepx++)
for (int stepy = ; stepy < lm && j + stepy <= M ; stepy++)
{
if (id[i + stepx][j + stepy])
slover.Link(cas,id[i + stepx][j + stepy]);
}
cas++;
}
}
slover.ansd = INF;
slover.Dance();
printf("%d\n",slover.ansd);
}
return ;
}

POJ 1084 Square Destroyer

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXM = ;
const int MAXN = ;
const int MAXNODE = MAXN * MAXM;
const int INF = 0x3f3f3f3f;
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++)
H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = ;
for(int c = R[] ; c != ; c = R[c])v[c] = true;
for(int c = R[] ; c != ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} void Dance(int d)
{
if(d + f() > ansd)return;
if(R[] == )
{
ansd = min(ansd,d);
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
Dance(d + );
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return;
}
}; DLX slover;
int n;
int a[][][];
int id[][];
int b[];
bool f[]; int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
int tot = ( * n + ) * n + n;
for (int i = ; i <= tot ; i++) f[i] = true;
int m,v;
scanf("%d",&m);
while (m--)
{
scanf("%d",&v);
f[v] = false;
}
int num = ;
for (int i = ; i <= n + ; i++)
{
for (int j = ; j <= n ; j++)
id[ * i - ][j] = ++num;
if (i <= n)
{
for (int j = ; j <= n ; j++)
id[ * i][j] = ++num;
}
}
int cnt = ;
for (int i = ; i <= tot ; i++)
{
if (f[i]) b[i] = ++cnt;
}
num = ;
memset(a,-,sizeof(a));
for (int i = ; i <= n ; i++)
{
for (int j = ; j <= n ; j++)
for (int k = ; i + k - <= n && j + k - <= n ; k++)
{
bool flag = true;
for (int x = ; x < k ; x++)
if (!f[id[ * i - ][j + x]]) flag = false;
for (int x = ; x < k ; x++)
if (!f[id[ * (i + k - ) + ][j + x]]) flag = false;
for (int x = ; x < k ; x++)
if (!f[id[ * (i + x)][j - ]]) flag = false;
for (int x = ; x < k ; x++)
if (!f[id[ * (i + x)][j + k - ]]) flag = false;
if (!flag) continue;
a[i][j][k] = ++num;
}
}
slover.init(cnt,num);
for (int i = ; i <= n ; i++)
for (int j = ; j <= n ; j++)
{
for (int k = ; i + k - <= n && j + k - <= n ; k++)
{
if (a[i][j][k] != -)
{
for (int x = ; x < k ; x++)
{
slover.Link(b[id[ * i - ][j + x]],a[i][j][k]);
slover.Link(b[id[ * (i + k - ) + ][j + x]],a[i][j][k]);
slover.Link(b[id[ * (i + x)][j - ]],a[i][j][k]);
slover.Link(b[id[ * (i + x)][j + k - ]],a[i][j][k]);
}
}
}
}
slover.ansd = INF;
slover.Dance();
printf("%d\n",slover.ansd);
}
return ;
}

POJ 3074 Sudoku

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int INF = 0x3f3f3f3f;
const int N = ;
const int MAXN = N * N * N + ;
const int MAXM = N * N * + ;
const int MAXNODE = MAXN * + MAXM + ;
int g[MAXN];
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ; i <= m ; i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i - ;
R[i] = i + ;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++) H[i] = -;
} void link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c] ; i != c ; i = D[i])
for(int j = R[i] ; j != i ; j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
for(int j = L[i] ; j != i ; j = L[j])
++S[Col[U[D[j]] = D[U[j]] = j]];
L[R[c]] = R[L[c]] = c;
} bool Dance(int d)
{
if(R[] == )
{
for(int i = ;i < d ; i++)g[(ans[i] - ) / N] = (ans[i] - ) % + ;
for(int i = ;i < N * N ; i++)
{
printf("%d",g[i]);
// if (i % N == N - 1) putchar('\n');
}
return true;
}
int c = R[];
for(int i = R[] ; i != ; i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c] ; i != c ; i = D[i])
{
ans[d] = Row[i];
for(int j = R[i] ; j != i ; j = R[j]) Remove(Col[j]);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j]) resume(Col[j]);
}
resume(c);
return false;
}
}; DLX slover;
int G[][];
char str[]; void place(int &r,int &c1,int &c2,int &c3,int &c4,int i,int j,int k)
{
r = (i * N + j) * N + k;
c1 = i * N + j + ;
c2 = N * N + (i * N + k);
c3 = N * N * + (j * N + k);
c4 = N * N * + ((i / ) * + (j / )) * N + k;
} int main()
{
//freopen("sample.txt","r",stdin);
while (scanf("%s",str) != EOF)
{
if (strcmp(str,"end") == ) break;
int cas = ;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
char tmp = str[cas];
cas++;
if (tmp == '.') G[i][j] = -;
else G[i][j] = tmp - '';
}
}
int r,c1,c2,c3,c4;
slover.init(N * N * N ,N * N * );
for (int i = ; i < N ; i++)
for (int j = ; j < N ; j++)
for (int k = ; k <= ; k++)
{
if (G[i][j] == - || G[i][j] == k)
{
place(r,c1,c2,c3,c4,i,j,k);
slover.link(r,c1);
slover.link(r,c2);
slover.link(r,c3);
slover.link(r,c4);
}
}
slover.Dance();
putchar('\n');
}
return ;
}

ZOJ 3122 Sudoku

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int INF = 0x3f3f3f3f;
const int N = ;
const int MAXN = N * N * N + ;
const int MAXM = N * N * + ;
const int MAXNODE = MAXN * + MAXM + ;
char g[MAXN];
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ; i <= m ; i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i - ;
R[i] = i + ;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++) H[i] = -;
} void link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c] ; i != c ; i = D[i])
for(int j = R[i] ; j != i ; j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
for(int j = L[i] ; j != i ; j = L[j])
++S[Col[U[D[j]] = D[U[j]] = j]];
L[R[c]] = R[L[c]] = c;
} bool Dance(int d)
{
if(R[] == )
{
for(int i = ;i < d ; i++)g[(ans[i] - ) / N] = (ans[i] - ) % N + 'A';
for(int i = ;i < N * N ; i++)
{
printf("%c",g[i]);
if (i % N == N - ) putchar('\n');
}
return true;
}
int c = R[];
for(int i = R[] ; i != ; i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c] ; i != c ; i = D[i])
{
ans[d] = Row[i];
for(int j = R[i] ; j != i ; j = R[j]) Remove(Col[j]);
if(Dance(d + ))return true;
for(int j = L[i] ; j != i ; j = L[j]) resume(Col[j]);
}
resume(c);
return false;
}
}; void place(int &r,int &c1,int &c2,int &c3,int &c4,int i,int j,int k)
{
r = (i * N + j) * N + k;
c1 = i * N + j + ;
c2 = N * N + i * N + k;
c3 = N * N * + j * N + k;
c4 = N * N * + ((i / ) * + j / ) * N + k;
} DLX slover;
char str[][]; int main()
{
//freopen("sample.txt","r",stdin);
bool first = true;
while (scanf("%s",str[]) == )
{
if (first) first = false;
else putchar('\n');
for (int i = ; i < ; i++)scanf("%s",str[i]);
slover.init(N * N * N,N * N * );
int r,c1,c2,c3,c4;
for (int i = ; i < N ; i++)
for(int j = ; j < N ; j++)
for (int k = ; k <= N ; k++)
{
if (str[i][j] == '-' || str[i][j] == 'A' + k - )
{
place(r,c1,c2,c3,c4,i,j,k);
slover.link(r,c1);
slover.link(r,c2);
slover.link(r,c3);
slover.link(r,c4);
}
}
slover.Dance();
}
return ;
}

HDU 4069 Squiggly Sudoku

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int N = ; //3*3数独
const int MAXN = N*N*N + ;
const int MAXM = N*N* + ;
const int MAXNODE = MAXN* + MAXM + ;
char g[MAXN];
int cnt;
struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ansd,ans[MAXN]; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ;i <= n;i++)H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz]=c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
L[R[c]] = L[c]; R[L[c]] = R[c];
for(int i = D[c];i != c;i = D[i])
for(int j = R[i];j != i;j = R[j])
{
U[D[j]] = U[j];
D[U[j]] = D[j];
--S[Col[j]];
}
} void resume(int c)
{
for(int i = U[c];i != c;i = U[i])
for(int j = L[i];j != i;j = L[j])
++S[Col[U[D[j]]=D[U[j]]=j]];
L[R[c]] = R[L[c]] = c;
} void Dance(int d)
{
if(cnt > )return;
if(R[] == )
{
for(int i = ;i < d;i++)g[(ans[i]-)/] = (ans[i]-)% + '';
cnt++;
return;
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
Remove(c);
for(int i = D[c];i != c;i = D[i])
{
ans[d] = Row[i];
for(int j = R[i];j != i;j = R[j])Remove(Col[j]);
Dance(d+);
if(cnt > )return;
for(int j = L[i];j != i;j = L[j])resume(Col[j]);
}
resume(c);
}
}; DLX slover;
int id[][];
int a[][]; void bfs(int sx,int sy,int d)
{
queue<pair<int,int> >q;
q.push(make_pair(sx,sy));
id[sx][sy] = d;
while(!q.empty())
{
pair<int,int> tmp = q.front();
int x = tmp.first;
int y = tmp.second;
q.pop();
if(x > && ((a[x][y]% ) / ) == )
if(id[x - ][y] == -)
{
id[x - ][y] = d;
q.push(make_pair(x - ,y));
}
if(x < N - && ((a[x][y] % ) / ) == )
if(id[x + ][y] == -)
{
id[x + ][y] = d;
q.push(make_pair(x + ,y));
}
if(y > && ((a[x][y]) / ) == )
if(id[x][y - ] == -)
{
id[x][y - ] = d;
q.push(make_pair(x,y - ));
}
if(y < N - && ((a[x][y] % ) / ) == )
if(id[x][y + ] == -)
{
id[x][y + ] = d;
q.push(make_pair(x,y + ));
}
}
} int main()
{
int T,kase = ;
scanf("%d",&T);
while (T--)
{
for (int i = ; i < N ; i++)
for (int j = ; j < N ; j++) scanf("%d",&a[i][j]);
memset(id,-,sizeof(id));
int index = ;
for (int i = ; i < N ; i++)
for (int j = ; j < N ; j++)
{
if (id[i][j] == -)
bfs(i,j,++index);
} /* for (int i = 0 ; i < N ; i++)
{
for (int j = 0; j < N ; j++)
printf("%d ",id[i][j]);
putchar('\n');
}
*/
slover.init(N * N * N,N * N * );
for (int i = ; i < N ; i++)
for (int j = ; j < N ; j++)
for (int k = ; k <= N ; k++)
{
if (a[i][j] % != && a[i][j] % != k) continue;
int r = (i * N + j) * N + k;
int c1 = i * N + j + ;
int c2 = N * N + i * N + k;
int c3 = N * N * + j * N + k;
int c4 = N * N * + (id[i][j] - ) * N + k;
slover.Link(r,c1);
slover.Link(r,c2);
slover.Link(r,c3);
slover.Link(r,c4);
}
cnt = ;
slover.Dance();
printf("Case %d:\n",kase++);
if (cnt == ) puts("No solution");
else if (cnt > ) puts("Multiple Solutions");
else
{
for (int i = ; i < N * N ; i++)
{
printf("%c",g[i]);
if (i % N == N - ) putchar('\n');
}
} }
return ;
}

HDU 3335 Divisibility 这个题不是DLX不知道为啥放到专题里了。也放到这吧

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int MAXN = ;
const int MAXM = MAXN * ;
struct Edge
{
int u,v,next;
int w;
}edge[MAXM];
int head[MAXN],tot; void init()
{
memset(head,-,sizeof(head));
tot = ;
} void add_edge(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = head[u];
head[u] = tot++;
} int linker[MAXN];
bool used[MAXN];
int NX; bool dfs(int u)
{
for (int i = head[u] ; i != - ; i = edge[i].next)
{
int v = edge[i].v;
if (!used[v])
{
used[v] = true;
if (linker[v] == - || dfs(linker[v]))
{
linker[v] = u;
return true;
}
}
}
return false;
} int calcu()
{
memset(linker,-,sizeof(linker));
int ret = ;
for (int i = ; i < NX ; i++)
{
memset(used,false,sizeof(used));
if (dfs(i)) ret++;
}
return ret;
} int N;
LL src[MAXN]; int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&N);
for (int i = ; i< N ; i++) scanf("%I64d",&src[i]);
sort(src,src + N);
N = unique(src,src + N) - src;
NX = N;
init();
for (int i = ; i < NX ; i++)
{
for (int j = ; j < NX ; j++)
{
if (i == j) continue;
if (src[j] % src[i] == ) add_edge(i,j,);
}
}
int ret = calcu();
printf("%d\n",NX - ret);
}
return ;
}

HDU 4979 A simple math problem.

DLX 打表

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
const int MAXN = * + ;
const int MAXM = * + ;
const int MAXNODE = MAXN * MAXM;
const int INF = 0x3f3f3f3f;
int a[] = {
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, };
/*struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ans[MAXN];
LL ansd; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = 0;i <= m;i++)
{
S[i] = 0;
U[i] = D[i] = i;
L[i] = i-1;
R[i] = i+1;
}
R[m] = 0; L[0] = m;
sz = m;
for(int i = 1 ; i <= n ; i++)
H[i] = -1;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < 0)H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = 0;
for(int c = R[0] ; c != 0 ; c = R[c])v[c] = true;
for(int c = R[0] ; c != 0 ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} void Dance(int d)
{
if(d + f() >= ansd)return;
if(R[0] == 0)
{
ansd = min(ansd,1LL * d);
return;
}
int c = R[0];
for(int i = R[0];i != 0;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
Dance(d + 1);
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return;
}
}; DLX slover;
int a[MAXN],b[MAXN];
LL C[20][20];
void init2()
{
C[0][0] = 1;
for (int i = 1 ; i < 20 ; i++)
{
C[i][0] = C[i][i] = 1;
for (int j = 1 ; j < i ; j++)
C[i][j] = C[i -1][j] + C[i -1][j - 1];
}
} int main()
{
init2();
int N,M,R;
int kase = 1;
for (int n = 0 ; n < 9 ; n++)
for (int m = 0 ; m < 9 ; m++)
for (int r = 0 ; r < 9 ; r++)
{
if (n == 0 && m == 0 && r == 0){ printf("0, "); continue;}
if (!(r <= m && m <= n)) {printf("0, "); continue;}
if (n == 8 && m == 5 && r == 4) {printf("20, "); continue;}
int cnt1 = 0;
int cnt2 = 0;
for (int i = 0 ; i < (1 << n) ; i++)
{
int cc = 0;
for (int j = 0 ; j < n ; j++)
if (i & (1 << j)) cc++;
if (cc == m) a[++cnt1] = i;
if (cc == r) b[++cnt2] = i;
}
slover.init(cnt1,cnt2);
for (int i = 1 ; i <= cnt1 ; i++)
for (int j = 1 ; j <= cnt2 ; j++)
if ((a[i] | b[j]) == a[i])
slover.Link(i,j);
LL tmp = C[n][r];
LL tmp2 = C[m][n];
slover.ansd = tmp;
slover.Dance(0);
printf("%d, ",slover.ansd);
}
return 0;
}*/ int main()
{
int T,kase = ;
scanf("%d",&T);
while (T--)
{
int n,m,r;
scanf("%d%d%d",&n,&m,&r);
if (n == && m == && r == ) printf("Case #%d: %d\n",kase++,);
else
{
printf("Case #%d: %d\n",kase++,a[n * * + m * + r]);
}
}
return ;
}

HDU 5046 Airport

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
const int MAXN = ;
const int MAXM = ;
const int MAXNODE = MAXN * MAXM;
const int INF = 0x3f3f3f3f;
int N,K; struct DLX
{
int n,m,sz;
int U[MAXNODE],D[MAXNODE],R[MAXNODE],L[MAXNODE],Row[MAXNODE],Col[MAXNODE];
int H[MAXN],S[MAXM];
int ans[MAXN];
LL ansd; void init(int _n,int _m)
{
n = _n;
m = _m;
for(int i = ;i <= m;i++)
{
S[i] = ;
U[i] = D[i] = i;
L[i] = i-;
R[i] = i+;
}
R[m] = ; L[] = m;
sz = m;
for(int i = ; i <= n ; i++)
H[i] = -;
} void Link(int r,int c)
{
++S[Col[++sz] = c];
Row[sz] = r;
D[sz] = D[c];
U[D[c]] = sz;
U[sz] = c;
D[c] = sz;
if(H[r] < )H[r] = L[sz] = R[sz] = sz;
else
{
R[sz] = R[H[r]];
L[R[H[r]]] = sz;
L[sz] = H[r];
R[H[r]] = sz;
}
} void Remove(int c)
{
for(int i = D[c] ; i != c ; i = D[i])
L[R[i]] = L[i], R[L[i]] = R[i];
} void resume(int c)
{
for(int i = U[c] ; i != c ; i = U[i])
L[R[i]] = R[L[i]] = i;
} bool v[MAXNODE];
int f()
{
int ret = ;
for(int c = R[] ; c != ; c = R[c])v[c] = true;
for(int c = R[] ; c != ; c = R[c])
if(v[c])
{
ret++;
v[c] = false;
for(int i = D[c] ;i != c ;i = D[i])
for(int j = R[i] ;j != i ; j = R[j])
v[Col[j]] = false;
}
return ret;
} void Dance(int d)
{
if (ansd <= K) return;
if(d + f() >= ansd)return;
if(R[] == )
{
if (ansd > d) ansd = d;
return;
}
int c = R[];
for(int i = R[];i != ;i = R[i])
if(S[i] < S[c])
c = i;
for(int i = D[c];i != c;i = D[i])
{
Remove(i);
for(int j = R[i] ; j != i ; j = R[j])Remove(j);
Dance(d + );
for(int j = L[i] ; j != i ; j = L[j])resume(j);
resume(i);
}
return;
}
}; DLX slover;
struct point
{
LL x,y;
}src[MAXN]; bool judge(LL mid)
{
slover.init(N,N);
for (int i = ; i <= N ; i++)
{
for (int j = ; j <= N ; j++)
{
LL dis = 1LL * abs(src[i].x - src[j].x) + 1LL * abs(src[i].y - src[j].y);
if (dis <= mid) slover.Link(i,j);
}
}
slover.ansd = 1e14;
slover.Dance();
if (slover.ansd <= K) return true;
return false;
} int main()
{
int T,kase = ;
scanf("%d",&T);
while (T--)
{
scanf("%d%d",&N,&K);
for (int i = ; i <= N ; i++) scanf("%I64d%I64d",&src[i].x,&src[i].y);
LL L = ,R = 1e12;
LL ans = ;
while (L < R)
{
LL mid = L +(R - L) / ;
if (judge(mid)) R = mid;
else L = mid + ;
}
// int ans = R;
// if (judge(R - 1)) ans = R - 1;
printf("Case #%d: %I64d\n",kase++,L);
}
return ;
}

Dancing Links [Kuangbin带你飞] 模版及题解的更多相关文章

  1. Kuangbin 带你飞 数位DP题解

    以前一直不知道该咋搞这个比较好. 感觉推起来那个数字好麻烦.后来有一种比较好的写法就是直接的DFS写法.相应的ismax表示当前位是否有限制. 数位DP也是有一种类似模版的东西,不过需要好好理解.与其 ...

  2. kuangbin带你飞 最短路 题解

    求一个图最短路边的办法.好像下面的那个有问题.单向边和双向边一定是有区别的.这个比较容易.参照该文的最短路网络流题目和连通图题目一题求最短路关节边 另外上述2个题目的代码好像有问题. 在UVALIVE ...

  3. kuangbin带你飞 后缀数组 题解

    2份模板 DC3 . 空间复杂度O3N 时间复杂度On #define F(x) ((x) / 3 + ((x) % 3 == 1 ? 0 : tb)) #define G(x) ((x) < ...

  4. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  5. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  6. Tarjan 联通图 Kuangbin 带你飞 联通图题目及部分联通图题目

    Tarjan算法就不说了 想学看这 https://www.byvoid.com/blog/scc-tarjan/ https://www.byvoid.com/blog/biconnect/ 下面是 ...

  7. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  8. 「kuangbin带你飞」专题十四 数论基础

    layout: post title: 「kuangbin带你飞」专题十四 数论基础 author: "luowentaoaa" catalog: true tags: mathj ...

  9. 「kuangbin带你飞」专题二十 斜率DP

    layout: post title: 「kuangbin带你飞」专题二十 斜率DP author: "luowentaoaa" catalog: true tags: mathj ...

随机推荐

  1. cocos2d-x 精灵

    Sprite有两个父类:BatchableNode批量创建精灵(大量重复的比如子弹)和pyglet.sprite.Sprite. 精灵的创建

  2. C语言运算符(注意事项)

    1.C语言取余注意事项:%   a.求余.模运算符(%)时要求两数必须是整型数据. b.取余的结果,是取决于被除数   (不管除数是正数 还是 负数,模的符号与被除数的符号相同).   例:8÷2=4 ...

  3. Django,Celery, rabbitmq

    学习Django 2 by Example书中的456页,运行 celery -A myshop worker -l info 报错.虽然特别指定了Celery的版本,也没用.之前使用的是标准安装:下 ...

  4. IP数据报格式 及分组转发算法

    ip数据报分首部和数据两部分组成: 首部分为固定部分和可变部分 版本——占 4 位,指 IP 协议的版本 目前的 IP 协议版本号为 4 (即 IPv4) 首部长度——占 4 位,可表示的最大数值 是 ...

  5. web相关基础知识3

    一 .浮动布局   ★元素浮动之后不占据原来的位置,脱离标准流 ★浮动的盒子在一行上显示 ★行内元素浮动之后转换为行内块元素.(不推荐使用,会脱离标准流,转行内元素最好使用display: inlin ...

  6. 延迟加载(Lazyload)三种实现方式

    定义:延迟加载也称为惰性加载,即在长网页中延迟加载图像.用户滚动到它们之前,视口外的图像不会加载.这与图像预加载相反,在长网页上使用延迟加载将使网页加载更快.在某些情况下,它还可以帮助减少服务器负载. ...

  7. java有几种对象(PO,VO,DAO,BO,POJO)

    首先,java有几种对象(PO,VO,DAO,BO,POJO) 一.PO:persistant object 持久对象,可以看成是与数据库中的表相映射的java对象.使用Hibernate来生成PO是 ...

  8. stap中的entry函数

    只有在ret probe函数中,在这个函数中才会使用@entry函数去提取变量 是因为ret probe 有什么特殊的吗?在中间这个变量会变化吗? A new operator, @entry, is ...

  9. httpclient upload file

    用httpclient upload上传文件时,代码如下: HttpPost httpPost = new HttpPost(uploadImg); httpPost.addHeader(" ...

  10. 【bzoj1806】[Ioi2007]Miners 矿工配餐 dp

    题目描述 有n个物品,每个都是3种之一.现要将这n个物品分成两个序列,对于每个序列中的每个物品,可以得到 它及它前面相邻的两个物品(不足则取全部)中不同种类的个数 的收益.问最大的总收益. 输入 输入 ...