f0vea
BAN USER#include <iostream>
#include <queue>
using namespace std;
int careerSolution(int m, int n)
{
int steps[m][n];
bool visited[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
steps[i][j] = 0;
visited[i][j] = false;
}
}
steps[0][0] = 1;
visited[0][0] = true;
class coord {
public:
coord(int lhs, int rhs)
{
x = lhs;
y = rhs;
}
coord operator=(coord& rhs){
this->x = rhs.x;
this->y = rhs.y;
}
int x;
int y;
};
coord start(0, 0);
queue<coord> q;
q.push(start);
int dx[3] = { 1, 0, 1 };
int dy[3] = { 0, 1, 1 };
while(!q.empty()){
coord current = q.front();
q.pop();
for(int i = 0; i < 3; i++){
coord next(current.x + dx[i], current.y + dy[i]);
if(next.x < m && next.y < n){
steps[next.x][next.y] += steps[current.x][current.y];
if(!visited[next.x][next.y]){
q.push(next);
visited[next.x][next.y] = true;
}
}
}
}
return steps[m-1][n-1];
}
- f0vea January 07, 2017