-
-
Save ArthurLoboLobo/c9928fd81ba2957662222bb3176d3ea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int n, m, vis[15][15], resposta = 0; | |
int xe, ye, xs, ys; | |
bool inside(int i, int j) { | |
if(i >= 1 && i <= n && j >= 1 && j <= m) return true; | |
return false; | |
} | |
void dfs(int i, int j, int d) { | |
vis[i][j] = 1; | |
if(i == xs && j == ys) { | |
resposta = max(resposta,d); | |
vis[i][j] = 0; | |
return; | |
} | |
if(inside(i-2,j) && vis[i-2][j] == 0) dfs(i-2,j,d+2); | |
if(inside(i+2,j) && vis[i+2][j] == 0) dfs(i+2,j,d+2); | |
if(inside(i,j-2) && vis[i][j-2] == 0) dfs(i,j-2,d+2); | |
if(inside(i,j+2) && vis[i][j+2] == 0) dfs(i,j+2,d+2); | |
vis[i][j] = 0; | |
} | |
int main() { | |
cin >> n >> m; | |
cin >> xe >> ye; | |
cin >> xs >> ys; | |
dfs(xe,ye,1); | |
cout << resposta << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment