Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sam is a tourist, One day he plans to go one country where there are N cities and each pair of city is connected to each other by a bidirectional road. Sam want to visit each city exactly once and he wants to start in one city and end in another city after traveling exactly N-1 roads. You have given a String[] path. If the j-th column of the i-th row of paths is '1', he must travel the road that connects city i and city j.


Suppose there are three cities(A,B,C), and Sam want to travel path between city A to city C. So there are 6 possible paths P(3,2)=6. For this example String[]path is {"001","000","100"} But only 4 paths allowed for Sam that are (B->A->C),(A->C->B),(B->C->A),(C->A->B) and paths( A->B->C) and (C->B->A) are not allowed because path A->C or C->A is not covered.
Posted

You problem looks like the "Traveling Salesman"[^] with the additional path constraint. It can be effectively solved using, for instance, Simulated Annealing[^].

BTW I see a contraddiction in your example:
suryakannan wrote:
path is {"001","000","100"}

Doesn't the above mean A->C and C->A are the only allowed connections?
 
Share this answer
 
v2
Comments
Member 7939459 10-Sep-11 3:44am    
send complete code
CPallini 10-Sep-11 5:43am    
Nope. You're requested to.
Good luck.
:-)
Emilio Garavaglia 14-Sep-11 7:54am    
corrected a broken link
CPallini 14-Sep-11 7:56am    
Thank you.
If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, or learn the Magic Words: "Do you want fries with that?"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900