当前位置:网站首页>2022 Hangzhou Electric Multi school first Dragon Slayer (dfs+ state compression)
2022 Hangzhou Electric Multi school first Dragon Slayer (dfs+ state compression)
2022-07-24 18:48:00 【Dusk of fools】
#include <iostream>
#include <cstring>
#include <algorithm>
#define f first
#define s second
using namespace std;
typedef long long LL;
typedef pair<double,double> PDD;
const int N=50,M=1<<15;
int n,m,k;
int f[M];
int pd[N][N],zq[N][N],hq[N][N];// Judge whether you have passed , Longitudinal wall , Cross wall ;
struct node{
int x[2],y[2];
}dui[N];
int x1,x2,ys,y2;
void init(){
memset(pd,0,sizeof pd);
memset(zq,0,sizeof zq);
memset(hq,0,sizeof hq);
}
int find(int x){// Find the number of removed walls corresponding to each state
int cs=0;
for(int i=0;i<k;i++){
cs+=x>>i&1;
}
return cs;
}
int dfs(int x,int y){
if(x==x2&&y==y2) return 1;
int res=0;
if(x-1>=0&&pd[x-1][y]==0&&zq[x][y]==0){
pd[x-1][y]=1;
res=max(dfs(x-1,y),res);
pd[x-1][y]=0;
}
if(x+1<n&&pd[x+1][y]==0&&zq[x+1][y]==0){
pd[x+1][y]=1;
res=max(dfs(x+1,y),res);
pd[x+1][y]=0;
}
if(y-1>=0&&pd[x][y-1]==0&&hq[x][y]==0){
pd[x][y-1]=1;
res=max(dfs(x,y-1),res);
pd[x][y-1]=0;
}
if(y+1<m&&pd[x][y+1]==0&&hq[x][y+1]==0){
pd[x][y+1]=1;
res=max(res,dfs(x,y+1));
pd[x][y+1]=1;
}
return res;
}
bool check(int s){
init();// Initialize array
for(int i=0;i<k;i++){// Drawing
if(((s>>i)&1)==0){
if(dui[i].x[0]==dui[i].x[1]){
for(int j=dui[i].y[0];j<dui[i].y[1];j++){
zq[dui[i].x[0]][j]++;
}
}
else{
for(int j=dui[i].x[0];j<dui[i].x[1];j++){
hq[j][dui[i].y[0]]++;
}
}
}
}
pd[x1][ys]=1;
return dfs(x1,ys);//dfs Judge whether this state can reach the end
}
int main(){
int t;
cin>>t;
while(t--){
int ans=20;
cin>>n>>m>>k;
memset(f,0,sizeof f);
cin>>x1>>ys>>x2>>y2;
for(int i=0;i<k;i++){
cin>>dui[i].x[0]>>dui[i].y[0]>>dui[i].x[1]>>dui[i].y[1];
if(dui[i].x[0]>dui[i].x[1]) swap(dui[i].x[0],dui[i].x[1]);
if(dui[i].y[0]>dui[i].y[1]) swap(dui[i].y[0],dui[i].y[1]);
}
for(int i=0;i<1<<k;i++){// Traversal state
if(f[i]==0&&find(i)<ans){// prune
f[i]=check(i);
if(f[i]){
ans=min(ans,find(i));
}
}
}
cout<<ans<<endl;
}
return 0;
}边栏推荐
- Eternal Blue ms17-010exp reappears
- Today's sleep quality record 79 points
- EasyUI framework dialog repeated loading problem
- 13. What is the difference between onkeydown, up and onkeypress?
- Network security port 80 - PHP CGI parameter injection Execution Vulnerability
- 【微信小程序开发】自定义tabBar案例(定制消息99+小红心)
- Ionic4 learning notes 9 -- an east project 01
- [today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
- 2022杭电多校第一场Dragon slayer(dfs+状态压缩)
- matplotlib
猜你喜欢

CF. Bits And Pieces(子集状压dp + 剪枝)

Crazy God redis notes 11

Getting started with MySQL database

Sqoop

狂神redis笔记11

Today's sleep quality record 79 points
![[wechat applet development] custom tabbar case (custom message 99 + little hearts)](/img/49/354ecb448e91d9e15aaec4922a62e1.png)
[wechat applet development] custom tabbar case (custom message 99 + little hearts)

Web

EasyUI adds row level buttons to the DataGrid

FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(下)
随机推荐
PCIe link initialization & Training
Introduction to VIM
Principle and application of database
Cryptography knowledge - Introduction to encryption -1
Typora user manual
Windowing function (1) - top three employees of department salary
OPENGL学习(三)GLUT二维图像绘制
CF. Bits And Pieces(子集状压dp + 剪枝)
[wechat applet development] custom tabbar case (custom message 99 + little hearts)
The problem that files cannot be uploaded to the server using TFTP is solved
TCL programming style guide
What are the benefits of knowledge management in enterprises?
[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
Crazy God redis notes 11
轻松学Pytorch-迁移学习实现表面缺陷检查
Some buckles
Understand corners_ Align, two perspectives for viewing pixels
Missing value processing
ETL development tool kettle download installation environment construction and use tutorial
JS to achieve progress steps (small exercise)