Assuming this is not some sort of an ACM problem that has to run very quickly, you can just do a depth first search and keep a counter of the possibilities.
When an appropriate possibility is reached, print it out.
And yes, I would also like to know where you got the question...
Comment