Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- vector<vector<int>>g(200, vector<int>(200,0));
- int len,n,m;
- string s;
- void dfs(int i, int j, int num) {
- if ((i < 0) || (j < 0) || (i > n) || (j > m))
- return;
- if (num == len) {
- g[i][j] = 1;
- return;
- }
- if (s[num] == 'R')
- dfs(i, j + 1, num + 1);
- else if (s[num] == 'L')
- dfs(i, j - 1, num + 1);
- else if (s[num] == 'U')
- dfs(i - 1, j, num + 1);
- else if (s[num] == 'D')
- dfs(i + 1, j, num + 1);
- else {
- dfs(i, j - 1, num + 1);
- dfs(i, j + 1, num + 1);
- dfs(i - 1, j, num + 1);
- dfs(i + 1, j, num + 1);
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int x, y;
- cin >> n >> m >> x >> y;
- n--;m--;x--;y--;
- cin >> s;
- len = s.length();
- dfs(x,y,0);
- for (int i = 0; i <= n;i++) {
- for (int j=0; j<=m; j++)
- cout << g[i][j] << " ";
- cout << "\n";
- }
- }
Add Comment
Please, Sign In to add comment