Hdu2102 (dfs) Search questions

Source: Internet
Author: User

Hdu2102 (dfs) Search questions

I won't say much about the meaning of this question. I can see that many people use bfsA, And then I use dfs to do the same thing as other deep searches. I just need to pay attention to some pruning in it. Otherwise, it will easily time out.



# Include
# Include
# Include
Using namespace std;


Char map [5] [15] [15];
Int mark [5] [15] [15], t, n, m, flash;
Int dir [4] [2] = {, 0,-, 0 };
Int dfs (int x, int y, int z, int tt)
{
Int I, xx, yy, zz;
If (map [x] [y] [z] = 'P ')
{
Flash = 1;
Return 0;
}
Else if (map [x] [y] [z] = '#')
{
If (x = 0) xx = 1;
Else xx = 0;
Yy = y;
Zz = z;
If (mark [xx] [yy] [zz] = 0 & map [xx] [yy] [zz]! = '*')
{
Mark [xx] [yy] [zz] = 1;
Dfs (xx, yy, zz, tt );
Mark [xx] [yy] [zz] = 0;
}
}
Else
{
For (I = 0; I <4; I ++)
{
Xx = x;
Yy = y + dir [I] [0];
Zz = z + dir [I] [1];
If (yy <0 | yy> = n | zz <0 | zz> = m) continue;
If (tt + 1> t) continue;
If (mark [xx] [yy] [zz] = 0 & map [xx] [yy] [zz]! = '*')
{
Mark [xx] [yy] [zz] = 1;
Dfs (xx, yy, zz, tt + 1 );
Mark [xx] [yy] [zz] = 0;
}
}
}
Return 0;
}
Int main ()
{
Int T, I, j;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n, & m, & t );
For (I = 0; I Scanf ("% s", map [0] [I]);
For (I = 0; I Scanf ("% s", map [1] [I]);
Map [0] [0] [0] = '.';
Memset (mark, 0, sizeof (mark ));
Mark [0] [0] [0] = 1;
Flash = 0;
Dfs (0, 0, 0 );
If (flash) printf ("YES \ n ");
Else printf ("NO \ n ");
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.