Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- bool checkPoda(string s){
- string allizzwell = "ALLIZZWELL";
- for(int i = 0; i < s.size(); i++)
- if(s[i]!=allizzwell[i]) return false;
- return true;
- }
- int DIR[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
- void BackTracking(string s, vector<vector<string> > matrix, int m, int n, int posi, int posj){
- if(s == "ALLIZZWELL"){
- cout << "YES" << endl;
- return;
- }else if(!checkPoda(s)){
- return;
- }else{
- // 8 casos posibles: estoy en posi, posj: ¿donde puedo ir?
- vector<string> posvalidas (8,s);
- vector<int> posvalidas2 (8,0); // 0 si se puede, 1 si no
- for (int i = 0; i < 8; ++i) {
- int x = posi + DIR[i][0], y = posj + DIR[i][1];
- if (x < 0 || x >= m || y < 0 || y >= n) continue;
- BackTracking(s + matrix[x][y], matrix, m, n, x, y);
- }
- }
- }
- int main(){
- int m = 3;
- int n = 6;
- vector<vector<string> > matrix(m, vector<string>(n));
- matrix[0] = {"A","W","E",".","Q","X"};
- matrix[1] = {"L","L","L",".","E","O"};
- matrix[2] = {"I","Z","Z","W","L","L"};
- string s = "";
- for(int i = 0; i < m; i++){
- for(int j = 0; j < n; j++){
- BackTracking(s,matrix,m,n,i,j);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement