如何使用回溯算法找到所有可能的解决方案 [英] How to find all possible solution using backtracking algorithm

查看:116
本文介绍了如何使用回溯算法找到所有可能的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello..i有一组不同的正确整数,并且需要一系列这样的数字,以便两个连续数字之间的差异是一个增加或减去一个例如:我有以下数字:1,2, 2,1,3,4,4,5,5,6

变为:1,2,1,2,3,4,5,4,5,6

或变为:1,2,1,2,3,4,5,6,5,4

这组数字无解:1,1,2,2, 3,4,4,5,5,7

现在我想写一个回溯算法来找到这个问题的所有可能的解决方案......任何人都可以帮助我



我尝试了什么:



我尝试了很多但没有找到解决方案

Hello..i have a set of different correct integers and a series of this numbers is required so that the difference between two consecutive numbers is either one increase or minus one for example: i have the following numbers: 1 , 2 , 2 , 1 , 3 , 4 , 4 , 5 , 5 , 6
it becomes : 1 , 2 , 1 , 2 , 3 , 4 , 5 , 4 , 5 , 6
or becomes: 1 , 2 , 1 , 2 , 3 , 4 , 5 , 6 , 5 , 4
and this set of numbers has no solution :1 , 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 7
now i want to write a backtracking algorithm to find all possible solution to this issue... anyone can help me

What I have tried:

I tried a lot but did not find a solution

推荐答案

引用:

任何人都可以帮助我



不,因为你想要的帮助是做我的家庭作业

HomeWork问题是你会遇到的问题的简化版本我必须在现实生活中解决,他们的目的是学习和练习

我们不做你的HomeWork。

HomeWork不会测试你乞求别人做你的工作的技能,它会让你思考和帮助您的老师会检查您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请展示您的代码并解释这个问题,我们可能会提供帮助。



展示您的工作并解释您的确切问题。


No because the help you want is "Do my HomeWork"
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

Show your work and explain what is you exact problem.

引用:

我尝试了很多但没有找到解决方案

I tried a lot but did not find a solution



回溯算法并不复杂,它是反复试验。

你当时开始编写一个解决方案1号码,当你到达一个没有可能号码的点时,你必须回去到上一步并尝试另一个号码。

回溯 - 维基百科 [ ^ ]


我的解决方案很短,因为我我没有为您的问题提供代码解决方案。通常,您将*不需要任何回溯算法。相反,您将不得不使用经典遗传算法(GA)来生成解集(即数字)。确保您将找到并使用客观适应度函数来选择与您期望获得的结果完全对应的内容,就像您在问题中列出的那样。 :)
My solution is very short, since I'm not providing a code solution for your question. Normally, you will *NOT* need any of backtracking algorithms. Instead, you'll have to use a classical genetic algorithm (GA) to produce sets of solutions (i.e. numbers). Make sure that you'll find and use objective fitness function to select that exactly correspond to the results you're expecting to obtain as just you've listed in your question. :)


看看这个页面:回溯解释 - Andrea Iacono - Medium [ ^ ]。
Have a look at this page: Backtracking explained – Andrea Iacono – Medium[^].


这篇关于如何使用回溯算法找到所有可能的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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