当前位置:网站首页>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;
}边栏推荐
- Ionic4 learning notes 4 -- add a tab page
- core dump
- Eternal Blue ms17-010exp reappears
- 3. Variable declaration promotion?
- vim相关介绍
- 引发0xC0000005内存违例几种可能原因分析
- Latex mathematical formula
- The difference between static method and instance method
- FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(下)
- OPENGL学习(五)Modern OpenGL 三角形绘制
猜你喜欢

OPENGL学习(三)GLUT二维图像绘制

Mysqlworkbench performance analysis tool -- Performance dashboard

Inoic4 learning notes 2

Windowing function (1) - top three employees of department salary

Cryptography knowledge - Introduction to encryption -1

Escape character in JS?

4. Basic type and reference type?

网络安全80端口—-PHP CGI参数注入执行漏洞

FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(上)

EasyUI framework dialog repeated loading problem
随机推荐
OPENGL学习(四)GLUT三维图像绘制
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
Ionic4 learning notes 3
core dump
Latex数学公式
Latex mathematical formula
Mysqlworkbench performance analysis tool -- Performance dashboard
Convolution neural network receptive field calculation Guide
[wechat applet development] custom tabbar case (custom message 99 + little hearts)
Introduction to nipple music theory and personal perception
【TkInter】布局管理和事件系统
OPENGL学习(五)Modern OpenGL 三角形绘制
epoch,batch_ size
SATA protocol OOB essay
L4L7负载均衡
FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(下)
1. Typeof view variable type?
Calling startActivity() from outside of an Activity context requires the FLAG_ ACTIVITY_ NEW_ TASK flag
引发0xC0000005内存违例几种可能原因分析
TCL programming style guide