3 solutions
-
0
#include<bits/stdc++.h> using namespace std; int dx[2] = {1, 0}; int dy[2] = {0, 1}; vector<vector<int>> jl; vector<int> t; int n, m; int cnt = 0; void dfs(int x, int y, int depth) { t.push_back(x); t.push_back(y); jl.push_back(t); t.clear(); if (x == n && y == m) { cnt++; cout << cnt << ":"; for (unsigned int i = 0;i < jl.size() - 1;i++) { cout << jl[i][0] << "," << jl[i][1] << "->"; } cout << n << "," << m << endl; return; } int nx , ny; for (int i = 0;i < 2;i++) { nx = x + dx[i]; ny = y + dy[i]; if (ny > 0 && ny <= m && nx > 0 && nx <= n) { dfs(nx, ny, depth + 1); jl.pop_back(); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; dfs(1, 1, 0); return 0; }
Information
- ID
- 697
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- 5
- Tags
- # Submissions
- 247
- Accepted
- 88
- Uploaded By