题目链接 有一个n*m(1<=n,m<=20)的网格图,图中有k堵墙和有一条长度为L(L<=8)的蛇,蛇在移动的过程中不能碰到自己的身体.求蛇移动到点(1,1)所需的最小步数. 显然用8个(x,y)来表示蛇的状态是不现实的(用哈希也很难存下,要么爆内存,要么超时),所以首先应当进行状态压缩.可以发现蛇的身体是连续的,因此可以用一个表示方向的向量来储存蛇身体的每个部分在它上个部分的哪个方向(只有头部用(x,y)表示),这样总状态数就变成了n*m*(2^((L-1)*2)),在可接受范围内了…
POJ 1324 Holedox Moving (状压BFS) Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18091 Accepted: 4267 Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring comes, Holedox wakes up, moves to the…
poj 1324 Holedox Moving 题目地址: http://poj.org/problem?id=1324 题意: 给出一个矩阵中,一条贪吃蛇,占据L长度的格子, 另外有些格子是石头, 不能通过, 请问蛇到达 (1,1)格子最短距离. 明显的BFS问题, 将每一个可以走的格子进入队列, 格子判断能否走?(给蛇身体标序号(蛇头l, 蛇尾1,其他置为0), 当 fabs(cur_num - tmp_num)>=l 的时候,说明蛇的身体已经离开之前的格子了. #include <ios…
题目地址: http://poj.org/problem?id=1324 优先队列---A*的估价函数不能为蛇头到(1,1)的距离,这样会出错. 看了discuss,有大神说这题A*的估价函数为BFS (0,0)到各点的花费在乘上10 ,但是还是不清楚,希望知道的可以给我留个言,谢谢了. 思路: 用0,1,2,3表示方向,这样就可以用四进制状态压缩了. 总共需要3+3*4^1+……3*4^6. 推荐大家能不用STL就不用STL,太浪费时间了. 下面是用STL超时代码和用数组模拟AC代码. 超时代…
题意:有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱, 如果没有去过就付R的钱.求的是最少要花多少钱. 析:BFS,然后由于走的路线不同,甚至边或者点都可能多走,所以用状态压缩.然后本题有坑啊,有重连,而且有很多条重边,所以多走几次就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include…
题目网址:http://poj.org/problem?id=1753 题目: Flip Game Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying ei…
http://poj.org/problem?id=1324 Holedox Moving Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17042   Accepted: 4065 Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring comes, Holedox wakes…
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7357    Accepted Submission(s): 2552 Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)……这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带…
Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip 3 to 5 p…
Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he contacts you, one of his human friends, for help. The jail area is a rectangle contains n×m little grids, each grid might be one of the following: ) Empt…