The password is a total of 500-bit complete wide-search password. one of the conditions is a multiple of N. Therefore, a maximum of 1-15 characters in the 4999 medium-search status may appear.
Simple code
# Include <stdio. h>
# Include <string. h>
# Include <queue>
# Include <iostream>
Using namespace STD;
Int n, m, C, Mark [20], visit [5100];
Struct Node
{
Int Len;
Int PRT [510];
} A, B;
Int judge (node S)
{
Int I, T = 0;
For (I = 1; I <= S. Len; I ++)
{
T = (T * C + S. PRT [I]) % N;
}
Return T;
}
Int print (node S)
{
For (INT I = 1; I <= S. Len; I ++)
{
If (S. PRT [I] <= 9) printf ("% d", S. PRT [I]);
Else printf ("% C", S. PRT [I]-10 + 'A ');
}
Printf ("\ n ");
Return 0;
}
Int BFS ()
{
Int I, j, x = 1;
Memset (visit, 0, sizeof (visit ));
A. Len = 0;
A. PRT [0] = 0;
Queue <node> q;
Q. Push ();
While (! Q. Empty ())
{
B = Q. Front ();
Q. Pop ();
For (I = 0; I <16; I ++)
{
If (! Mark [I]) continue;
If (x = 1 & I = 0) continue; // the first digit cannot be set to zero.
A = B;
A. Len = B. Len + 1;
A. PRT [A. Len] = I;
Int K = judge ();
If (k = 0)
{
Print ();
Return 1;
}
If (visit [k]) continue;
If (A. Len <= 499 );
{
Visit [k] = 1;
Q. Push ();
}
}
X ++;
}
Return 0;
}
Int main ()
{
Int T, I, J;
Char STR [15];
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N, & C );
Scanf ("% d", & M );
Memset (mark, 0, sizeof (Mark ));
For (I = 1; I <= m; I ++)
{
Scanf ("% s", STR );
If (STR [0]> = '0' & STR [0] <= '9 ')
Mark [STR [0]-'0'] = 1;
Else
Mark [STR [0]-'A' + 10] = 1;
}
If (n = 0)
{
If (MARK [0]) printf ("0 \ n ");
Else printf ("give me the bomb please \ n ");
}
Else
{
Int flash = BFS ();
If (! Flash) printf ("give me the bomb please \ n ");
}
}
Return 0;
}
Hdu1226 search for water problems