【HDOJ】1010 Tempter of the Bone

【题目】http://acm.hdu.edu.cn/showproblem.php?pid=1010

【报告】

    一看这题目,哇,好简单啊,暴力DFS。然后TLE了……

    然后百度了一下,别人都用了个什么叫奇偶性剪枝的东西,我不是很懂,大概抄了一下,然后就AC了。

    关于奇偶性剪枝的东西,有两个网站:http://www.cppblog.com/Geek/archive/2010/04/26/113615.html还有http://baike.baidu.com/view/7789287.htm
【程序】

// TASK: 1010 Tempter of the Bone
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <queue>
#define N 10
#define T 60
using namespace std;
const long fx[5]={0,1,0,-1,0};
const long fy[5]={0,0,1,0,-1};
long a[N+1][N+1];
long n,m,t;
long sx,sy,tx,ty;
long b[N+1][N+1];                         // 记录该点到终点的最短路径
inline bool calc(long x,long y,long t)
{
      // cout << x << " " << y << " " << t << endl;
       if (b[x][y]>t) return false;
       if (a[tx][ty]==1) return false;
       if ((t-b[x][y])%2==1) return false;
       if (t<0) return false;
       else if (t==0) return (tx==x&&ty==y);
       else
       {
           a[x][y]=1;
           for (long i=1;i<=4;i++)
               if (a[x+fx[i]][y+fy[i]]==0&&calc(x+fx[i],y+fy[i],t-1))
                  return true;
           a[x][y]=0;
           return false;
       }
}
class point
{
      public:
             long x,y;
             point (long X=0,long Y=0)
             {
                   x=X,y=Y;
             }
};
queue<point> qq;
inline void bfs()
{
       while (!qq.empty()) qq.pop();
       point x(tx,ty),y;
       b[tx][ty]=0;
       qq.push(x);
     
posted @ 2012-08-29 11:21  为美好世界献上珂学  阅读(160)  评论(0)    收藏  举报