当前位置:网站首页>Fzu 1686 dragon mystery repeated coverage
Fzu 1686 dragon mystery repeated coverage
2022-07-06 21:20:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
exchange 0,1 Model , Such as . Be careful , The range of data
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
using namespace std;
const int MaxM = 500;
const int MaxN = 500;
const int maxnode = MaxM*MaxN;
int K,n,m;
struct DLX
{
int n,m,size;
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)
{
ands=0x3f3f3f3f;
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;
size = m;
for(int i = 1;i <= n;i++)
H[i] = -1;
}
void Link(int r,int c)
{
++S[Col[++size]=c];
Row[size] = r;
D[size] = D[c];
U[D[c]] = size;
U[size] = c;
D[c] = size;
if(H[r] < 0)H[r] = L[size] = R[size] = size;
else
{
R[size] = R[H[r]];
L[R[H[r]]] = size;
L[size] = H[r];
R[H[r]] = size;
}
}
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()>=ands) return;
if(R[0] == 0) {ands=min(ands,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);
}
}
}g;
int mp[20][20],sa,sb,id[20][20];
int main()
{
while(~scanf("%d%d",&n,&m))
{
int tot=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%d",&mp[i][j]);
if(mp[i][j]) id[i][j]=++tot;
}
}
scanf("%d%d",&sa,&sb);
g.init(n*m,tot);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int ii=i,cnt=1;cnt<=sa&&ii<n;ii++,cnt++)
{
for(int jj=j,cnt2=1;cnt2<=sb&&jj<m;jj++,cnt2++)
{
if(mp[ii][jj])
{
g.Link(i*m+j+1,id[ii][jj]);
}
}
}
}
}
g.Dance(0);
printf("%d\n",g.ands);
}
return 0;
}
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117105.html Link to the original text :https://javaforall.cn
边栏推荐
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- js中,字符串和数组互转(一)——字符串转为数组的方法
- JS operation DOM element (I) -- six ways to obtain DOM nodes
- 039. (2.8) thoughts in the ward
- Math symbols in lists
- Nodejs教程之Expressjs一篇文章快速入门
- 爱可可AI前沿推介(7.6)
- SAP UI5 框架的 manifest.json
- 2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
- 如何实现常见框架
猜你喜欢
Aiko ai Frontier promotion (7.6)
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
966 minimum path sum
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
039. (2.8) thoughts in the ward
Deployment of external server area and dual machine hot standby of firewall Foundation
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
每个程序员必须掌握的常用英语词汇(建议收藏)
967- letter combination of telephone number
Fastjson parses JSON strings (deserialized to list, map)
随机推荐
SAP UI5 框架的 manifest.json
JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
爱可可AI前沿推介(7.6)
Aiko ai Frontier promotion (7.6)
Start the embedded room: system startup with limited resources
JS get array subscript through array content
FZU 1686 龙之谜 重复覆盖
PHP saves session data to MySQL database
Three schemes of SVM to realize multi classification
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
技术分享 | 抓包分析 TCP 协议
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
In JS, string and array are converted to each other (I) -- the method of converting string into array
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
Nodejs tutorial expressjs article quick start
首批入选!腾讯安全天御风控获信通院业务安全能力认证
js中,字符串和数组互转(二)——数组转为字符串的方法
Nodejs tutorial let's create your first expressjs application with typescript
JS traversal array and string
Is it profitable to host an Olympic Games?