View Code of Problem 3499

#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stdio.h>

using namespace std;

bool endres = false;
vector<pair<int,int> > res;
vector<pair<int, int> > way { {0,1},{1,0},{0,-1},{-1,0} };

void dfs(int maze[][6], int x, int y, int k)
{
	if (x < 0 || y < 0 || x >= 5 || y >= 5 || maze[x][y] == 1)
		return;
	res[k] = pair<int, int>(x,y);
	if (x == 4 && y == 4)
	{
		for (int i = 0; i <= k; i++)
			printf("(%d, %d)\n", res[i].first, res[i].second);
		endres = true;
		return;
	}
	for (int i = 0; i < 4; i++)
	{
		if (endres)
			return;
		maze[x][y] = 1;
		dfs(maze, x + way[i].first, y + way[i].second, k + 1);
		maze[x][y] = 0;
	}
}

int main()
{
	int maze[5+1][5+1];
	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++)
			cin >> maze[i][j];
	res.resize(5*5);
	dfs(maze,0,0,0);
	return 0;
}
/*
F:\temp\22478481.12011\Main.cc:16: error: in C++98 'way' must be initialized by constructor, not by '{...}'
F:\temp\22478481.12011\Main.cc:16: error: no matching function for call to 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::vector(<brace-enclosed initializer list>)'
stl_vector.h:241: note: candidates are: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >]
stl_vector.h:227: note:                 std::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >]
stl_vector.h:215: note:                 std::vector<_Tp, _Alloc>::vector(const _Alloc&) [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >]
stl_vector.h:207: note:                 std::vector<_Tp, _Alloc>::vector() [with _Tp = std::pair<int, int>, _Alloc = std::allocator<std::pair<int, int> >]
*/

Double click to view unformatted code.


Back to problem 3499