-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompter les chemins vers la sortie.c
58 lines (54 loc) · 1.47 KB
/
Compter les chemins vers la sortie.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
struct Labyrinthe
{
char Case;
int visite;
};
int Parcourir(int x, int y, struct Labyrinthe **Cases, int L, int C)
{
int Ywassal = 0;
Cases[y][x].visite = 1;
if (y == L - 1 && x == C - 2)
Ywassal++;
if (y + 1 < L && Cases[y + 1][x].Case == '.' && !Cases[y + 1][x].visite)
{
Ywassal += Parcourir(x, y + 1, Cases, L, C);
Cases[y + 1][x].visite = 0;
}
if (y - 1 > 0 && Cases[y - 1][x].Case == '.' && !Cases[y - 1][x].visite)
{
Ywassal += Parcourir(x, y - 1, Cases, L, C);
Cases[y - 1][x].visite = 0;
}
if (x + 1 < C && Cases[y][x + 1].Case == '.' && !Cases[y][x + 1].visite)
{
Ywassal += Parcourir(x + 1, y, Cases, L, C);
Cases[y][x + 1].visite = 0;
}
if (x - 1 > 0 && Cases[y][x - 1].Case == '.' && !Cases[y][x - 1].visite)
{
Ywassal += Parcourir(x - 1, y, Cases, L, C);
Cases[y][x - 1].visite = 0;
}
return Ywassal;
}
int main()
{
int L, C;
scanf("%d %d", &L, &C);
struct Labyrinthe **Cases = (struct Labyrinthe **)malloc(L * sizeof(struct Labyrinthe *));
getchar();
for (int i = 0; i < L; i++)
{
Cases[i] = (struct Labyrinthe *)malloc(C * sizeof(struct Labyrinthe));
for (int j = 0; j < C; j++)
{
scanf("%c", &Cases[i][j].Case);
Cases[i][j].visite = 0;
}
getchar();
}
printf("%d", Parcourir(0, 1, Cases, L, C));
return 0;
}