Answer the question
In order to leave comments, you need to log in
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
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.
Try to solve the problem using dynamic programming. It may even work in general terms.
#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");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question