Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[8][8],n,m,xc,yc,ok;
- int dx[]={-2,-2,-1,-1,1,1,2,2};
- int dy[]={-1,1,-2,2,-2,2,-1,1};
- int interior(int x,int y)
- {
- return x>0&&x<=n&&y>0&&y<=m;
- }
- void afis()
- {
- ok=1;
- for(int i=1;i<=n;++i)
- {
- for(int j=1;j<=m;++j)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- void BKT(int k,int x,int y)
- {
- if(ok==0)
- {
- int xv,yv;
- a[x][y]=k;
- if(k==n*m)
- afis();
- else
- {
- for(int i=0;i<8;++i)
- {
- xv=x+dx[i]; yv=y+dy[i];
- if(interior(xv,yv)&&a[xv][yv]==0)
- BKT(k+1,xv,yv);
- }
- }
- a[x][y]=0;
- }
- }
- int main()
- {
- cin>>n>>m>>xc>>yc;
- BKT(1,xc,yc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement