HDU 1010 Tempter of the Bone

题目链接

5Y。。。。居然是因为一个剪枝减导致第一次WA,然后又悲剧了3次,最后感觉自己的程序没啥问题啊,自己乱查 数据,自己想出了一组没有过。。。。

3 4  11

S..D

....

....

终于发现某 一个小的剪枝错了。。。。。这个题杭电文档上搜索的例题,所以剪枝也 没有怀疑,自己实现的 时候搞错了。。。450ms+。。。慢死。。。

 1 #include <stdio.h>
 2 #include <string.h>
 3 char p[10][10];
 4 int o[10][10],n,m,t,endr,endc,z;
 5 int a[4] = {0,0,1,-1};
 6 int b[4] = {1,-1,0,0};
 7 void dfs(int x,int y,int step)
 8 {
 9     int i;
10     o[x][y] = 1;
11     if(z) return ;
12     if(step == t&&x == endr&&y == endc)
13     {
14         z = 1;
15         return ;
16     }
17     else if(step > t)
18     return ;
19     for(i = 0;i <= 3;i ++)
20     {
21         if(x+a[i] >= 0&&y+b[i] >= 0&&x+a[i] <= n-1&&y+b[i] <= m-1)
22         {
23             if(o[x+a[i]][y+b[i]] == 0)
24             {
25                 dfs(x+a[i],y+b[i],step+1);
26                 o[x+a[i]][y+b[i]] = 0;
27             }
28         }
29     }
30     o[x][y] = 0;
31     return ;
32 
33 }
34 int main()
35 {
36     int i,j,strr,strc,z1;
37     while(scanf("%d%d%d%*c",&n,&m,&t)!=EOF)
38     {
39         z1 = z = 0;
40         memset(o,0,sizeof(o));
41         if(!n&&!m&&!t) break;
42         for(i = 0; i <= n-1; i ++)
43         {
44             for(j = 0; j <= m-1; j ++)
45             {
46                 scanf("%c",&p[i][j]);
47                 if(p[i][j] == 'S')
48                 {
49                     strr = i;
50                     strc = j;
51                 }
52                 else if(p[i][j] == 'D')
53                 {
54                     endr = i;
55                     endc = j;
56                 }
57                 else if(p[i][j] == 'X')
58                 {
59                     o[i][j] = 1;
60                 }
61             }
62             getchar();
63         }
64         if((strr+strc)%2 == (endr+endc)%2)
65         {
66             if(t%2)
67             z1 = 0;
68             else
69             z1 = 1;
70         }
71         else
72         {
73             if(t%2)
74             z1 = 1;
75             else
76             z1 = 0;
77         }
78         if(z1)
79         dfs(strr,strc,0);
80         else
81         z = 0;
82         if(z)
83         printf("YES\n");
84         else
85         printf("NO\n");
86     }
87     return 0;
88 }
posted @ 2012-07-09 11:02  Naix_x  阅读(160)  评论(0)    收藏  举报