Commit b1c19607 by Andrew Dahl

### Optimized Problem 15

parent 8064bff9
Showing with 5 additions and 19 deletions
 ... ... @@ -3,48 +3,34 @@ using namespace std; int size = 21; const int size = 21; map > route_grid; long int find_route(map > grid, int x, int y, bool test=false) long int find_route(int x, int y, bool test=false) { if(x < 0 || x >= size || y < 0 || y >= size || grid[x][y] == 1) if(x < 0 || x >= size || y < 0 || y >= size) return 0; grid[x][y] = 1; if(x == (size-1) && y == (size-1)) return 1; if(route_grid[x][y] == 0) return find_route(grid, x+1, y) + find_route(grid, x, y+1); return find_route(x+1, y) + find_route(x, y+1); return route_grid[x][y]; } int main() { map > grid; for(int i=0; i < size; i++) for(int j=0; j < size; j++) { grid[i][j] = 0; route_grid[i][j] = 0; } for(int i = size - 2; i >= 0; i--) for(int j = size - 2; j >=0; j--) route_grid[i][j] = find_route(grid,i,j,true); route_grid[i][j] = find_route(i,j,true); cout << route_grid[0][0] << endl; /*for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) cerr << " " << route_grid[i][j]; cerr << endl; }*/ return 0; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!