UVA - 658 It's not a Bug, it's a Feature!

这道题算是一道到隐式搜索题,将每一个状态转化为二进制,但是如果用将每个状态建成一个图,空间需要太大,不可行,所以运用,priority_queue优化的dijkstra算法,只需对现有的边进行转换即可

注意一点,优先队列优先最大,但是题目是优先最小,因为这样才能最优

这个题建图很有特色

#include
#include
#include
#include
#include
#include #include #include #define MST(vis,x) memset(vis,x,sizeof(vis)) #define INF 0x3f3f3f3f #define maxn 20 #define maxm 110 using namespace std; int n,m; char before[maxm][maxn+5],after[maxm][maxn+5]; int tim[maxm]; int d[(1<x.dis; } }; int dij() { MST(d,INF); MST(judge,0); node temp,tt; temp.bug=(1<q; q.push(temp); while(!q.empty()) { temp=q.top(); q.pop(); if(temp.bug==0)return temp.dis; if(judge[temp.bug])continue; judge[temp.bug]=1; for(int a=1;a<=m;a++) { int flag=0; for(int b=0;b 
   

 

转载于:https://www.cnblogs.com/tuquanrong/p/7357900.html

你可能感兴趣的:(UVA - 658 It's not a Bug, it's a Feature!)