此程序的c编码 [英] c coding for this program

查看:69
本文介绍了此程序的c编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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->

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.

推荐答案

您的问题看起来像 [模拟退火 [
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写道:
suryakannan wrote:

路径为{"001","000","100"}

path is {"001","000","100"}


上面的意思不是A->CC->A是唯一允许的连接吗?


Doesn''t the above mean A->C and C->A are the only allowed connections?


如果您要张贴作业,至少尝试使其看起来像您拥有的作业试图自己做点什么!

我们不做您的作业:这是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,或学习魔语:您要用它炸薯条吗?"
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?"


这篇关于此程序的c编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆