We're going to come back to this row and we're going to figure out not just this equilibrium, but all equilibria.
我们要回到这一排,我们将解决不仅这个均衡,而是所有的均衡
It's just not possible to solve some of these problems by hand and this isn't even a domain that's necessarily into the world of CS but speaks to you the applicability of it all.
手工处理这些问题似乎有些不大可能,但这还不是,计算机科学要解决的主要问题,我们的目的只是为了告诉你它的用途。
OK. I know. It looks boring. But it's a structure of the things I want to think about when I go through trying to take a problem and mapping it into a iterative program.
好,我知道这看起来有点无聊,但是这是我要去以迭代的方式,去解决一个问题采取的,措施的大致结构。
That's why there's a lot of emphasis on sharpening your teeth by doing this class of problems.
这就是为什么强调要通过解决这些问题,来提高你的能力
So that's the topic that I'd like to address today.
这就是我今天要解决的问题。
This solves a major problem which I'm going to talk about just at the beginning of class here in a slide or two, is how to get DNA into cells?
这解决了我要讲到的一个主要问题,就是在这节开始的一两张幻灯片中要讲的,怎样将DNA导入细胞的问题
Again, same kind of reasoning says, given some value x, I happened to pick a small one here, what's an easy way to do this? Well, let's just start at one. That's my variable I'm going to change and check.
好,尤其是,让我们到这里来,让我给大家看看第二个例子,让我把这个注释掉,这是我要解决的,第二个问题,假设我想找到一些整数的,所有除数,我想要找出来这个数的所有的除数。
Because if b was odd, then b minus one is even which means on the next step, I can cut the problem in half again.
这意味着我在下一步里解决的问题,规模要小了一半,好,课堂材料的第三题。
Once you hear that description, it's easy to write the code, in fact. This is a place where the recursive version of it is much easier to think about than the iterative one.
实际上一旦你听到了大致描述,就能很轻松的写出代码来,在这一点上应用递归来解决问题,比用迭代要容易理解多了。
So if I were to solve this problem, here's the way I would do it. I would say, first thing I want to do, is I want to input a value for the base as a float.
如果我想要解决这个问题,这就是我要解决它的方式了,第一件我要做的事情就是要,输入一个浮点数作为三角形的底。
Then, here is what we actually do.
然后,这就是我们真正要解决的问题
So this is kind of a modern show and that is kind of a retro language and it's also as will be one of the takeaways of this course completely irrelevant to what problem you are solving, the fact that this engineer is using--proclaiming to use Visual Basic really is not a compelling part of the story.
这看起来很时髦,像是重新流行的语言,当然,该语言是我们学习这门课程,过程中附带着要学习的,这与解决什么问题无关,事实上,使用VB真的不是,这个故事出彩的地方。
That gets us to the smart thief. Why is this thief smart? Because she took 600. And she learned 600 that in fact there is a good way to solve this problem. And that's what we're going to talk about next. And that's something called dynamic programming.
现在我们要当聪明的贼,这个贼为什么聪明呢?,因为它选择了,它知道这事实上是解决这个问题的好方法,这就是我们接下来要讲的,也就是动态编程。
That's the question we're going to try and address. If we can do this, this is good, because first of all, it removes any questions about what machine I'm running on, it's talking about fundamentally, how hard is this problem, and the second thing is, it is going to do it specifically in terms of the input. Which is one of the things that I was worried about.
这是一个我们接下来要去,尝试和解决的问题,如果我们能做到的话会很不错,因为首先,它解决了结果可能和我,运行的计算机有关系的问题,因为这从根本了告诉了,我们这个问题的复杂度,第二件事情,就是这种方法可以依据输入的大小来计算,而这正是我最担心的地方。
Is the first part. That says, I took the branch through here that eventually got to the end and said, there wasn't a solution, in which case I'mgoing to print out, there ain't no solution, otherwise I'll print out the pieces. All right, let's check it out. Ah, what did I say?
我是否返回了特殊的none值?是第一部分,这里的意思是我从这个分支,走到这儿最终走到最后,并告诉我这条路没有解决方案,也就是我想要打印的结果,没有符合的结果,否则我会把它们输出来?
应用推荐