硬是没看出来网络流和SPFA算法的写法
正解:SPFA(最短路)+分层图
我的乱搞算法:BFS+二进制状态压缩
考试的时候脑糊了,毕竟调了一上午,自闭了
巨坑:同一个单元格可能有多把钥匙 XSL
蒟蒻的乱搞代码
#include
#define re register int
using namespace std;
int n,m,p,k,s;
int MAP[11][11][11][11],key[11][11],vis[11][11][(1<<11)];
struct node
{
int a,b,tot,k;
};
const int dx[5]={0,1,-1,0,0},dy[5]={0,0,0,1,-1};
queueq;
int read()
{
int ans = 0;
char w = ' ', ch = getchar();
while(ch < '0' || ch > '9')
{
w = ch;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
ans = (ans << 3) + (ans << 1);
ans += ch - '0';
ch = getchar();
}
return (w == '-' ? -ans : ans);
}
bool check(int a1,int a2)
{
return (a1>=1 && a1<=n && a2>=1 && a2<=m);
}
int BFS()
{
q.push(node{1,1,0,key[1][1]});
vis[1][1][key[1][1]]=1;
while(!q.empty())
{
node now=q.front();
q.pop();
if(now.a==n && now.b==m)
{
return now.tot;
}
for(re i=1;i<=4;i++)
{
int f1=now.a+dx[i];
int f2=now.b+dy[i];
if(check(f1,f2))
{
if(MAP[now.a][now.b][f1][f2]==-1)
{
continue;
}
if(MAP[now.a][now.b][f1][f2]!=0)
{
if((now.k&(1<