计算目标数从数字一组 [英] Computing target number from numbers in a set

查看:160
本文介绍了计算目标数从数字一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,要求我这样的家庭作业问题:

I'm working on a homework problem that asks me this:

Tiven一有限组数字,以及一个目标数量,发现如果设置可以在使用基本的数学运算(加,子,多重峰格),并使用每个数字的集合来计算所述目标数量的正是一次(所以我需要用尽下集)。这要与递归方法来实现。

Tiven a finite set of numbers, and a target number, find if the set can be used to calculate the target number using basic math operations (add, sub, mult, div) and using each number in the set exactly once (so I need to exhaust the set). This has to be done with recursion.

因此​​,举例来说,如果我有一组

So, for example, if I have the set

{1, 2, 3, 4}

和目标10,那么我可以得到它使用

and target 10, then I could get to it by using

((3 * 4) - 2)/1 = 10. 

我想表达出该算法的伪code,但至今还没有得到太远。我想图是要走的路,但铁定AP $ P这个$ pciate帮助。谢谢。

I'm trying to phrase the algorithm in pseudo-code, but so far haven't gotten too far. I'm thinking graphs are the way to go, but would definitely appreciate help on this. thanks.

推荐答案

在思考如何解决问题(如使用图表),它确实有助于只是看待问题。如果你发现自己陷入了困境,并似乎无法拿出任何伪code,则很可能有一些是抱着你回来;一些其他的问题或关切的是,还没有被解决。在这种情况下的一个例子粘性的问题可能是,到底什么是递归这个问题?

Before thinking about how to solve the problem (like with graphs), it really helps to just look at the problem. If you find yourself stuck and can't seem to come up with any pseudo-code, then most likely there is something that is holding you back; Some other question or concern that hasn't been addressed yet. An example 'sticky' question in this case might be, "What exactly is recursive about this problem?"

在你阅读下一段,尽量先回答这个问题。如果你知道什么是递归这个问题,然后写一个递归的方法来解决它可能不会是非常困难的。

Before you read the next paragraph, try to answer this question first. If you knew what was recursive about the problem, then writing a recursive method to solve it might not be very difficult.

您想知道,如果使用一组数字(仅使用一次每个数字)一些前pression为您提供了一个目标值。有四个二进制操作,每一个。所以,换句话说,你要知道,如果与其他数字的一些前pression操作的第一个号码给你的目标。那么,换句话说,你要知道,如果'其他'号的一些前pression为[...]。如果不是,则使用与第一个号码的第一个操作并没有真正给你你需要什么,所以尝试其他欢声笑语。如果他们不工作,那么也许它只是是不是意味着要。

You want to know if some expression that uses a set of numbers (each number used only once) gives you a target value. There are four binary operations, each with an inverse. So, in other words, you want to know if the first number operated with some expression of the other numbers gives you the target. Well, in other words, you want to know if some expression of the 'other' numbers is [...]. If not, then using the first operation with the first number doesn't really give you what you need, so try the other ops. If they don't work, then maybe it just wasn't meant to be.

编辑:我想这对四家运营商的中缀EX pression没有括号,因为在原来的问题评论说,括号内添加是为了一个例子(为清楚起见?),并利用括号并没有明确说明。

I thought of this for an infix expression of four operators without parenthesis, since a comment on the original question said that parenthesis were added for the sake of an example (for clarity?) and the use of parenthesis was not explicitly stated.

这篇关于计算目标数从数字一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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