Advertisement
Guest User

Untitled

a guest
Sep 17th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. Problem Description
  2. 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.
  3.  
  4.  
  5. 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. So you have to find the possible paths where String[] path is given..
  6. Instructions to use Open PBT Client:
  7. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory.
  8. Download the Support files by clicking the Get Support Files
  9. .
  10. You will find the problem directories containing:
  11. problem.h file
  12. problem.c file
  13. in your work directory.
  14. Write your solution in .c file
  15. Step 1:
  16. In your Solution File:
  17. Add Function int countPaths(char** paths)
  18. Step 2:
  19. Pass the following parameter to the function countPaths() path is a character pointer represents the path in a matrix format as mentioned in the problem description.
  20. Step 3:
  21. Write the appropriate code as mentioned in the problem description by following the below given Constraints.
  22. The input should be the character array for the method, which basically shows an nxn matrix for the desired garph (The connected Cities)
  23. This matrix shows which path Sam have to travel.
  24. You need to figure out the number of possible paths which covers the path that Sam have to travel.
  25. Your method should return the number of possible paths.
  26. If the char** paths is null then your method should return -1.
  27. The prototype of the function is:
  28. int countPaths(char** paths) Function will take a character pointer which is the representaion of the paths and return the feasible number of paths.
  29. Constraint:
  30. If the given path is null then return -1 ..
  31. Example 1
  32. Input: {"001","000","100"}
  33. Output:          4
  34. Example 2
  35. Input: {"000","100","000"}
  36. Output:          0
  37. Explanation:There is no path which is satisfying the above condition.
  38. For C solutions
  39. Header File       :
  40. FindPaths.h
  41. File Name         :
  42. FindPaths.c
  43. Function Name  :
  44. int countPaths(char** paths);
  45. For C++ solutions
  46. Header File
  47. :
  48. FindPaths.h
  49. Class Name
  50. :
  51. FindPaths
  52. Function Name
  53. :
  54. int countPaths(char** paths);
  55. FileName
  56. :
  57. FindPaths.cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement