M
M
Michael2011-06-19 16:54:33
Mathematics
Michael, 2011-06-19 16:54:33

How many path options are there for a 4x4 field, if you can walk right, down, right-down?

Is it considered according to the formula and where to dig?
And if there are 5?6?7 fields?
upd fixed a couple of typos

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
oandrew, 2011-06-19
@oandrew

I myself faced a similar problem, if I understood you correctly.
habrahabr.ru/qa/6563/
And here is a link where everything is described in detail
mathworld.wolfram.com/Self-AvoidingWalk.html
As a result, there is no general formula (
But this is if your task matches the way I understood you.

D
Disasm, 2011-06-19
@Disasm

Try to solve the problem using dynamic programming. It may even work in general terms.

O
oandrew, 2011-06-20
@oandrew


#include <iostream>
#include <cstdlib>
using namespace std;

#define ROWS 4
#define COLS 4

int f(int row, int col) {
    if(row == 0 && col == 0)
        return 1;
    int result = 0;
    if(row > 0)
        result += f(row - 1, col);
    if(row > 0 && col > 0)
        result += f(row - 1, col - 1);
    if(col > 0)
        result += f(row, col - 1);
    return result;
}
int main() {
    cout << f(ROWS - 1,COLS - 1);
    system("pause"); 
}

Here is the solution to the problem.
With 4x4 there will be 63

M
Michael., 2011-06-20
@kulinich

To clarify the conditions:
image
I think the author means this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question