Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("soarece.in");
- ofstream fout("soarece.out");
- int n,m,a[21][21],t[21][21],li,ci,lf,cf,nrsol;
- int dl[]={0,-1,0,1,0};
- int dc[]={0,0,1,0,-1};
- void citire()
- {
- int i,j;
- fin>>n>>m;;
- for(i=1;i<=n;i++)
- for(j=1;j<=m;j++)
- fin>>a[i][j];
- fin>>li>>ci>>lf>>cf;
- }
- void afis()
- {
- nrsol++;}
- void traseu(int l, int c, int pas)
- {
- int ln,cn,k;
- for(k=1;k<=4;k++)
- {
- ln=l+dl[k];
- cn=c+dc[k];
- if(ln>=1 && ln<=n && cn>=1 &&cn<=m)
- if(a[ln][cn]==0 &&t[ln][cn]==0)
- {
- t[ln][cn]=pas;
- if(ln==lf && cn==cf)
- afis();
- else
- traseu(ln,cn,pas+1);
- t[ln][cn]=0;
- }
- }
- }
- int main()
- {
- citire();
- t[li][ci]=1;
- traseu (li,ci,2);
- fout<<nrsol;;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement