Advertisement
CosminVarlan

MCIP_391

Oct 24th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("date.in");
  7. ofstream fout("date.out");
  8.  
  9.  
  10. int n, m;
  11. int a[11][11];
  12.  
  13. int dl[4]={-1,1,0,0};
  14. int dc[4]={0,0,-1,1};
  15. int s=0;
  16. int sol[100];
  17. int total_pasi = 0;
  18.  
  19. void afiseaza()
  20. {
  21.     for(int i=0; i<total_pasi; i++)
  22.     {
  23.         if (sol[i]==0) cout << "N ";
  24.         if (sol[i]==1) cout << "S ";
  25.         if (sol[i]==2) cout << "V ";
  26.         if (sol[i]==3) cout << "E ";
  27.     }
  28.     cout << endl;
  29.     cout << endl;
  30. }
  31.  
  32. void afism(){
  33.     for(int i=0; i<=n+1; i++)
  34.         {
  35.             for(int j=0; j<=m+1; j++)
  36.                 cout << a[i][j] << " ";
  37.             cout << endl;
  38.         }
  39.     cout << endl;
  40. }
  41.  
  42.  
  43. void bkt(int x, int y)
  44. {
  45.     //afism();
  46.     if (s==0) afiseaza();
  47.     else
  48.     {
  49.         for(int i=0; i<4; i++)
  50.         {
  51.             if (a[x+dl[i]][y+dc[i]]==0) continue;
  52.  
  53.             sol[total_pasi-s-1]=i;
  54.             a[x+dl[i]][y+dc[i]]--;
  55.             s--;
  56.             bkt(x+dl[i], y+dc[i]);
  57.             s++;
  58.             a[x+dl[i]][y+dc[i]]++;
  59.         }
  60.     }
  61. }
  62.  
  63.  
  64.  
  65.  
  66. int main()
  67. {
  68.     fin >> n >> m; // max 9
  69.     for(int i=1; i<=n; i++)
  70.         for(int j=1; j<=m; j++)
  71.         {
  72.             fin >> a[i][j];
  73.             s+=a[i][j];
  74.         }
  75.     total_pasi = s;
  76.  
  77.  
  78.  
  79.  
  80.     for(int i=1; i<=n; i++)
  81.         for(int j=1; j<=m; j++)
  82.         if (a[i][j]) {
  83.                 //cout <<"Incerc de la: "<< i << "  " << j << endl;
  84.                 a[i][j]--;
  85.                 s--;
  86.                 bkt(i,j);
  87.                 s++;
  88.                 a[i][j]++;
  89.         }
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement