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 59 60 61 62 63 64 65 66
|
#include <stdio.h>
//#include <string.h>
int check(int grid[12][12], int row);
int change_matrix(int grid[12][12], int row, int &sum);
//int print_str(int string);
int
main(void)
{
int sum = 0;
int subway[12][12] = {{0,1,0,0,0,0,0,0,0,0,0,0},
{1,0,1,1,1,1,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,1,1,0,0,1,1,0,0,0,0},
{0,1,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,1,0},
{0,0,0,0,1,1,0,0,1,1,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,1,1,1,1,0,1},
{0,0,0,0,0,0,0,0,0,0,1,0}};
change_matrix(subway, 0, sum);
printf("%d\n", sum);
return 0;
}
//Checks a row in the grid for a "1" and returns the column of the first "1" it finds.
//If there is no "1" in the row, this will return the value "12"
int
check(int grid[12][12], int row)
{
int i;
for(i = 0; i < 12; i++){
if(grid[i][row] == 1){
printf("%d %d\n", i, row);
return i;}
else if(i == 11)
return 12;
}
}
//If the position is at station L (column 11), the number of paths is increased by 1. If there
//were no other stations to go to (value of 12), then the program terminates. The program will
//then call itself again to complete the row and move on to the next station.
int
change_matrix(int grid[12][12], int row, int &sum)
{
int col;
col = check(grid, row);
if(row == 11){
/* strcat(string, "11");
print_str(string);*/
sum++;
return 0;}
else if(col == 12)
return 0;
else {grid[col][row] = 0;
grid[row][col] = 0;
change_matrix(grid, row, sum);
change_matrix(grid, col, sum);}
return 0;
}
|