当前位置:网站首页>FZU 1686 龙之谜 重复覆盖
FZU 1686 龙之谜 重复覆盖
2022-07-06 12:56:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
兑换0,1模型,如。注意,数据的范围
#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;
}版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117105.html原文链接:https://javaforall.cn
边栏推荐
- This year, Jianzhi Tencent
- Performance test process and plan
- 新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- Regular expression collection
- 【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
- What's the best way to get TFS to output each project to its own directory?
- Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
- Reflection operation exercise
- Ravendb starts -- document metadata
猜你喜欢

Is this the feeling of being spoiled by bytes?

愛可可AI前沿推介(7.6)

【论文解读】用于白内障分级/分类的机器学习技术

嵌入式开发的7大原罪

15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

Why do job hopping take more than promotion?

ICML 2022 | flowformer: task generic linear complexity transformer

OneNote in-depth evaluation: using resources, plug-ins, templates

1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
随机推荐
The biggest pain point of traffic management - the resource utilization rate cannot go up
OSPF multi zone configuration
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
What are RDB and AOF
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
Simple continuous viewing PTA
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
愛可可AI前沿推介(7.6)
Ravendb starts -- document metadata
Pat 1085 perfect sequence (25 points) perfect sequence
None of the strongest kings in the monitoring industry!
嵌入式开发的7大原罪
Reflection operation exercise
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
Deployment of external server area and dual machine hot standby of firewall Foundation
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
ACdreamoj1110(多重背包)
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices