Or a subset with the maximum value, there may be more than one, and you're done.
或者是有最大值的子问题集,可能不只一个子问题符合条件,然后就解决问题了。
And that may generalize again and it keeps going until you either get back to Adam and Eve, I guess. I don't think they were born in the US as far as I know, or you find somebody who satisfies that definition or you find that none of your parents actually are in that category.
降低到我的父亲或者母亲,是不是天生的美国公民呢,这个问题可以继续向下分解,你甚至可以追溯到亚当和夏娃的时候,据我所知它们并不是出生在美国的,或者你要么找到一个符合定义的人,要么发现你的父母都不满足条件。
Taking the problem, recognizing that you know what, 8 even though this is a pretty big problem size 8 in this case and last time it was size 8 or in the case of the papers in size of a thousand roughly with the phonebook, I assume these are in a perfectly straight line they won't quite fit.
以这个问题为例,你们要认识到,在这种情况下,这是个比较大的问题,其大小是,上次它的大小也是8,但在纸片那个问题中,电话簿的规模大概是上千的,现在假设这些,杯子完全在同一条直线上,虽然并不十分符合这个条件。
Computing square root. I'm going to capture it in a piece of code, I'm going to be able to refer to it by a name, and I'm going to suppress the details, meaning inside of that computation, you don't need to know what it does. You just need to know, if I give it the right kind of input, it'll give me back an input that satisfies the contract that I set up.
比如计算平方根,我会用一段代码来说明,我将给它命名,并且忽略细节,意思就是在这一段计算过程中,你不用知道它做了什么,你只需知道,如果我进行了正确的输入,它将会给我符合条件的输出。
And so the value of with i will be the value of i plus whatever I can get using the remaining items and decrementing the weight by the weight of i.
所以装上i之后的总价值,就是i的价值加上剩下物品中,符合条件者的所有价值,再在剩余重量中减去i的重量。
If it isn't, then I'm going to go back around the loop, and notice what happens. If I get all the way around the loop, that is, all the way through that FOR loop and I never find a path that takes me through here, then the last thing I'm going to do is return a pair or a tuple with a special simple number none twice.
如果没有,我会回到循环看看发生了什么,如果我运行了整个循环,也就是整个for循环,我仍没有找到符合条件的路径,那么我最后做的事情就是返回一对,或者一个数组的两次none值。
应用推荐