Posts

Showing posts with the label Alpro2

Program BackTracking

#include <stdio.h> #include <stdlib.h> /* macro to define limits*/ #define MAX_X 4 #define MAX_Y 9 #define END_X 3 #define END_Y 8 /* define structure for one point    with coordinate x and y */ typedef struct P{int x,y;}; /* functions to present path through matrix,    check if next move is valid    with backtrack technique */ void presentPath(P[],int); int tryC(int m[][MAX_Y],int,int); void checkPaths(int m[][MAX_Y],int,int,P[],int); int main() { /* declare start position and    matrix we are searching paths*/   int sX=0, sY=0,       m[MAX_X][MAX_Y]=      {       {0,0,0,1,1,1,0,0,0},       {1,1,0,0,0,0,0,0,0},       {1,0,1,0,0,1,0,1,0},       {0,0,1,1,0,1,1,1,0}      };     /* array that will serve to memorize the each path */   P Path[MAX_X+MAX_Y+1];     /* let...