3A的题目,第一次TLE,是因为一次BFS起点到终点状态太多爆掉了时间. 第二次WA,是因为没有枚举蛇的状态. 解体思路: 因为蛇的数目是小于5只的,那就首先枚举是否杀死每只蛇即可. 然后多次BFS,先从起点到第一把钥匙,不能往回走,要用VIS数组标记. 第二次从第一把钥匙走到第二把钥匙. 最后一次从最后一把钥匙走到终点即可. Tips 1: 在每次BFS过程中使用优先队列保证每次是最小步长的状态. Tips2 :使用二进制枚举蛇的状态 Tips3:首先使用DFS判断是否绝对有解,如果无解输出"…
题意:平面上有N个点(1≤N≤1000),若要新建边,费用是2点的欧几里德距离的平方.另外还有Q个套餐,每个套餐里的点互相联通,总费用为Ci.问让所有N个点连通的最小费用.(2组数据的输出之间要求有换行) 解法:利用二进制枚举套餐,时间复杂度是O(2QN2+N2logN).关于时间复杂度,枚举:二进制枚举为2Q,Kruskal为ElogE≈E≈N2:边排序:ElogE≈E≈N2.总的相加. 紫书上提到一个优化:不加任何套餐跑一遍MST(最小生成树),没有选的边便删除掉,因为以后加了套餐之后也选不…
题意:给一个地图,孙悟空(K)救唐僧(T),地图中'S'表示蛇,第一次到这要杀死蛇(蛇最多5条),多花费一分钟,'1'~'m'表示m个钥匙(m<=9),孙悟空要依次拿到这m个钥匙,然后才能去救唐僧,集齐m个钥匙之前可以经过唐僧,集齐x个钥匙以前可以经过x+1,x+2..个钥匙,问最少多少步救到唐僧. 解法:BFS,每个节点维护四个值: x,y : 当前坐标 key :已经集齐了key个钥匙 step:已经走了多少步 S :   蛇的访问状态 (2^5的数表示,某位为1表示已经杀过了) 然后把唐僧…
Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 903    Accepted Submission(s): 316 Problem Description This story happened on the background of Star Trek. Spock, the deputy captain of St…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3242    Accepted Submission(s): 1127 Problem Description <Journey to the West>…
Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 941    Accepted Submission(s): 352 Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Clas…
Description <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Zhu Bajie and Sha Wujing, escor…
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description   <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty.…
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩dp+广搜 使用dp[x][y][key][s]来记录孙悟空的坐标(x,y).当前获取到的钥匙key和打死的蛇s.由于钥匙具有先后顺序,因此在钥匙维度中只需开辟大小为10的长度来保存当前获取的最大编号的钥匙即可.蛇没有先后顺序,其中s的二进制的第i位等于1表示打死了该蛇,否则表示没打死.然后进行广度…
Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Zhu Bajie and Sha Wujin…