I'm new to C++. I'm solving the "Matrix walking problem", but I can't find the law of this question.The problem goes like this:
Given a pane of n*m cells, how many different paths are there from the upper left corner to the lower right corner?
You can only walk down or to the right at each step, and you can only walk along the edges of the matrix.
I don't know how to fix this, so please help me.
Thanks.
(my English is not well, sorry)
You can only walk down or to the right at each step, and you can only walk along the edges of the matrix.
Well, if you take the second statement at face value then there are only 2 such paths. Since I doubt that is what you mean then you had better have another go at translating it.
Otherwise, if you can step on any cell of the matrix then there are C(m+n-2,m-1) paths, since you have to choose (m-1) steps across and (n-1) steps down; i.e. you have to choose which of the (m-1)+(n-1) points you are going to put your (m-1) across steps.
If you can go across the centre of the matrix (which contradicts what you said) then there are
C(m+n-2,m-1) paths.
(That's a binomial coefficient, also written m+n-2Cm-1. Number of ways of choosing m-1 things from m+n-2 things.) Somewhere along the line you have to take m-1 steps across and n-1 steps down.