问题描述
Sam是一位游客,有一天他计划去一个有N个城市的国家,每对城市都通过一条双向道路相互连接. Sam希望只访问每个城市一次,他想在经过N-1条道路后从一个城市开始,然后在另一个城市结束.您已经给出了String []路径.如果第i行路径的第j列为"1",则他必须走连接城市i和城市j的道路.
假设有三个城市(A,B,C),并且山姆想在城市A到城市C之间旅行.因此有6条可能的路径P(3,2)= 6.对于此示例,String [] path为{"001","000","100"}},但Sam仅允许使用4条路径,即(B-> A-> C),(A-> C-> ; B),(B-> C-> A),(C-> A-> B)和路径(A-> B-> C)和(C-> B->不允许A),因为未覆盖路径A-> C或C-> A.因此,您必须找到给出String []路径的可能路径..
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. So you have to find the possible paths where String[] path is given..
推荐答案
这篇关于如何用C或C ++编写此程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!