当前位置:网站首页>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;
}边栏推荐
- Date function format conversion
- 8. = = and = = =?
- Sqoop
- 网络安全80端口—-PHP CGI参数注入执行漏洞
- Valentine's Day gift ----- use her photos and our chat records to generate word clouds~
- Mysql——》数据类型隐式转换
- 理解corners_align,两种看待像素的视角
- Zip compression and decompression
- 13. What is the difference between onkeydown, up and onkeypress?
- matplotlib
猜你喜欢

Escape character in JS?

L4L7负载均衡

EasyUI framework dialog repeated loading problem

matplotlib

【历史上的今天】7 月 24 日:Caldera 诉微软案;AMD 宣布收购 ATI;谷歌推出 Chromecast

多线程与并发编程常见问题(未完待续)

Understand corners_ Align, two perspectives for viewing pixels

Web

理解corners_align,两种看待像素的视角

Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
随机推荐
Data analysis of network security competition of national vocational college skills competition digital forensics-a
Cf. bits and pieces (subset pressing DP + pruning)
Sqoop
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
【TkInter】布局管理和事件系统
Type-C边充边听PD协议芯片
OPENGL学习(五)Modern OpenGL 三角形绘制
leetcode-记忆化深搜/动态规划v2
What are the benefits of knowledge management in enterprises?
Common problems of multithreading and concurrent programming (to be continued)
Windowing function (1) - top three employees of department salary
Ionic4 learning notes 5-- custom public module
2022暑期杭电多校第一场1012Alice and Bob(博弈论)
Excel practice notes 1
Web
Ionic4 learning notes 12 - a east project grid completes the list of goods
引发0xC0000005内存违例几种可能原因分析
Traversal and splicing of strings
Valentine's Day gift ----- use her photos and our chat records to generate word clouds~
PWN learning