Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int dx[4] = {-1,0,0,1};
- int dy[4] = {0,-1,1,0};
- int Px , Py , Ex, Ey, Sx,Sy;
- int A[4][4];
- int acceptable(int k){
- if ((Px + dx[k] >= 0) && (Py + dy[k] >= 0))
- if ((Px + dx[k] <= 3) && (Py + dy[k] <= 3))
- if (A[Px + dx[k]][Py + dy[k]] == 0)
- return 1;
- return 0;
- }
- int solution(int k, int i){
- if (Px == Ex && Py == Ey)
- return 1;
- return 0;
- }
- void printsolution(){
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- printf(" %d ", A[i][j]);
- printf("\n");
- }
- }
- void back(int i){
- for (int k = 0; k < 4; k++)
- if (acceptable(k)){
- A[Px + dx[k]][Py + dy[k]] = 1;
- Px = Px + dx[k];
- Py = Py + dy[k];
- if (solution(k, i)){
- printsolution();
- printf("\n");
- }
- else
- back(i + 1);
- A[Px][Py] = 0;
- Px = Px - dx[k];
- Py = Py - dy[k];
- }
- }
- int main(void){
- Sx = 0; Sy = 0;
- Ex = 3; Ey = 3;
- Px = 0; Py = 0;
- A[Px][Py] = 1;
- A[1][0] = 99;
- A[1][1] = 99;
- A[2][1] = 99;
- A[2][2] = 99;
- A[3][2] = 99;
- A[0][3] = 99;
- back(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement