And the first thing you do is ask is it an instance of some problem that other people have already solved?
而且你以前从没碰过这个问题,你首先要做的一件事就是问问自己,这是不是一个别人已经解决了的问题?
Now, when we talked about optimization problems in dynamic programming, I said there were two things to look for.
现在,当我们讨论,动态编程中的最优化问题时,我想说有两件事需要注意。
That's four items. Show up, sit down, and the first question is does anybody have a pen?
总共4件东西,你们来到,坐下,第一个问题是你们有带铅笔吗?
The second thing that he found was this group, they were always asking questions, -always asking questions, initially of their boss, later of their employees, of their partners, children, parents, friends.
他发现的第二件事是,这部分人,一直在问问题,一直问问题,最初是问他们的老板,后来是问他们的雇员,他们的搭档,孩子,父母,朋友。
And you can very quickly take this feature to an extreme 10 and start putting X and Y and A and B and 10 and all your variables up top because it would seem to solve all of your problems and stop all of your thinking, but it's generally not a good thing.
你可能迅速地使这个特征成为一个极端,开始把X和Y和A和B和0,和所有的变量都放在最前,因为好像它可以,解决你的所有问题,并中止你的想法,但通常这不是一件好事情。
I know this is a simple example, but when you mature as a programmer, one of the first things you should do when you sit down to tackle some problem is write something like this pseudo code.
我知道这是个很简单的例子,但是当你们成长为一名程序员后,当你们碰到问题后第一件事情就是,该写一些类似于,伪代码的东西。
I'm thinking about a problem, I'm going to show you an example in a second, first thing I'm going to do is say, what is the thing that's going to change every time I run through the same set of code?
我要解决一个问题,我马上会让大家看一个例子,第一件我要做的事情就是,弄明白每次运行同样的指令集时,每次都会改变的东西是什么?
And so frequently what we try and do is, we take a new problem and map it onto an old problem so that we can use an old solution.
我们经常做的一件事就是,我们处理一个新问题时,把它归结为一个老问题,以便我们能采取老的解决方式。
Well, what I always do in anything like this is, the first thing I do is, I run it on something where I can actually compute the answer in my head. So I get a sense of whether or not I'm doing the right thing.
好的,我常常在,这种问题中会做的是,我会做的第一件事是我,会先带入我可以心算的值来运行,因此我能够知道我是否做对了。
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.
如果我想要解决这个问题,这就是我要解决它的方式了,第一件我要做的事情就是要,输入一个浮点数作为三角形的底。
That's certainly one way to do it, but for computers that's not necessarily the easiest way. So another way of solving it is to do something we already saw last time, which is basically, why not simply enumerate all possible examples and check them?
将一个等式代入另一个等式,这当然是一种办法,但是对电脑来说这绝对不是一件简单的事,所以解决这个问题的办法,正如我们上一次看过的,非常基本?
One was overlapping sub-problems.
一件就是重叠的子问题。
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.
这是一个我们接下来要去,尝试和解决的问题,如果我们能做到的话会很不错,因为首先,它解决了结果可能和我,运行的计算机有关系的问题,因为这从根本了告诉了,我们这个问题的复杂度,第二件事情,就是这种方法可以依据输入的大小来计算,而这正是我最担心的地方。
The second thing is try every question because I give part marks.
第二件事就是尝试所有的问题,因为我会给部分分。
If I want to try and decide how to tackle a problem in an iterative matter, here the steps I'm going to go through. First thing I'm going to do, is I'm going to choose a variable that's going to count.
但是这就是我对它的观点,如果我试着去以迭代的方式,解决一个问题的话,下面是我应该采取的步骤,第一件要做的事情。
应用推荐