Following question was asked in a coding interview.how to solve it with out using dynamic programming?
# | User | Rating |
---|---|---|
1 | tourist | 3565 |
2 | Benq | 3540 |
3 | Petr | 3519 |
4 | maroonrk | 3503 |
5 | jiangly | 3391 |
6 | ecnerwala | 3363 |
7 | Radewoosh | 3349 |
8 | scott_wu | 3313 |
9 | ainta | 3298 |
10 | boboniu | 3289 |
# | User | Contrib. |
---|---|---|
1 | 1-gon | 198 |
2 | Errichto | 195 |
3 | rng_58 | 189 |
4 | awoo | 186 |
5 | SecondThread | 185 |
6 | Um_nik | 182 |
7 | vovuh | 177 |
8 | Ashishgup | 176 |
9 | antontrygubO_o | 175 |
10 | -is-this-fft- | 173 |
Following question was asked in a coding interview.how to solve it with out using dynamic programming?
Name |
---|
Auto comment: topic has been updated by leninkumar31 (previous revision, new revision, compare).
To reach from (0,0) to (X,Y) you need to go right X steps and go up Y steps. Let's regard a step as an arrow. If there is no building, you can make combinations of X right-arrows and Y up-arrows. That's C(X+Y,X) or equivalently C(X+Y,Y).
Now, there is a building that covers (A,B) to (A+N,B+M). Let f(X,Y) be the number of combinations can be made with X right-arrows and Y up-arrows. That is, f(X,Y) = C(X+Y,X) = C(X+Y,Y).
Then the number of pathes is as follows:
f(X,Y) — f(A+1,B+1)f(M-2,N-2)f(X-A-N+1,Y-B-M+1)
can you explain last equation in detail?
In fact it's wrong. I'm finding a new formula. But the idea was:
1
6 6
4 4 1 1
answer is 74. your solution is wrong.
A path should contain exactly one of arrows in the picture. (there are A up-arrows and B right-arrows)
So, the answer is: