Came back with an AC with 0.023 sec
Assume you could declare 25!/(12! 12!) array without MLE. But the resulting array only will have VERY few elements, most of them filled with null.
So you can replace them into a hashed set or something. Of course it will cost some time to check if a state has been visited, but it will not matter much since the number of the nodes are so small.
My program uses DFS, but searches not more than 1000 states per input case. (checked with an assert())
Observer, I lost my code for this one ... but I used BFS approach. As far as I can recall, I started from target state, find possible moves that are one-step away ... I repeated that it until at most 10 steps. I stored each possible move into a hash-list. After this, I just dealt with the inputs, if it's within 10 moves, it must be in my hash list.
-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
[cpp]Method Time (second) Memory States checked
TraceBack >7 >5M nearly 1000000
BFS(from begin to end) >4 >4M >100000
BFS(from end to begin) >2 >2M >10000
BFS(both way) 0.031 64K <2000[/cpp]
Finally I've got AC.
I've solved the problem using BFS and an optimising function wich counts how many knights aren't on their final place. The runtime was 0.035 seconds... pretty good.
Emilio, are you sure you've got those outputs for my inputs, with your AC program? cause my AC program does not give that answer.
Nothing is lost because everything is transforming.
Emilio, are you sure you've got those outputs for my inputs, with your AC program?
Yes, even I sent my code yesterday another time for confirming that was correct and I obtained AC (You can see my statistics http://acm.uva.es/cgi-bin/OnlineJudge?A ... 45242:Back), I sent it because I tought that was strange the output for my code. My code works fine, I think, it not prune its method is brute force. Maybe your code or mine is incorrect, but are AC