Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool checkPoda(string s){
  8.   string allizzwell = "ALLIZZWELL";
  9.   for(int i = 0; i < s.size(); i++)
  10.      if(s[i]!=allizzwell[i]) return false;
  11.   return true;
  12. }
  13.  
  14. int DIR[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
  15.  
  16. void BackTracking(string s, vector<vector<string> > matrix, int m, int n, int posi, int posj){
  17.   if(s == "ALLIZZWELL"){
  18.     cout << "YES" << endl;
  19.     return;
  20.   }else if(!checkPoda(s)){
  21.     return;
  22.   }else{
  23.     // 8 casos posibles: estoy en posi, posj: ¿donde puedo ir?
  24.     vector<string> posvalidas (8,s);
  25.     vector<int> posvalidas2 (8,0); // 0 si se puede, 1 si no
  26.  
  27.     for (int i = 0; i < 8; ++i) {
  28.         int x = posi + DIR[i][0], y = posj + DIR[i][1];
  29.         if (x < 0 || x >= m || y < 0 || y >= n) continue;
  30.         BackTracking(s + matrix[x][y], matrix, m, n, x, y);
  31.     }
  32.   }
  33. }
  34.  
  35.  
  36.  
  37. int main(){
  38.   int m = 3;
  39.   int n = 6;
  40.   vector<vector<string> > matrix(m, vector<string>(n));
  41.   matrix[0] = {"A","W","E",".","Q","X"};
  42.   matrix[1] = {"L","L","L",".","E","O"};
  43.   matrix[2] = {"I","Z","Z","W","L","L"};
  44.   string s = "";
  45.   for(int i = 0; i < m; i++){
  46.     for(int j = 0; j < n; j++){
  47.       BackTracking(s,matrix,m,n,i,j);
  48.     }
  49.   }
  50.   return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement