提交时间:2024-03-09 10:57:08

运行 ID: 136592

#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int dx[5] = {0 , 1 , 2, 2, 1}; int dy[5] = {0 , -2 , -1, 1 , 2}; int res[N]; bool f = false; int n , m; void dfs(int x , int y , int k) { if(x == n && y == n) { f = true; for(int i = 1 ; i < k ; i++) { cout << res[i] << " "; } return; } int xx , yy; for(int i = 1; i <= 4 ; i++) { xx = x + dx[i]; yy = y + dy[i]; if(!f && xx > 1 && xx <= n && yy >= 1 && yy <= m) { res[k] = i; dfs(xx , yy , k + 1); } } } int main() { int n , m; cin >> n >> m; dfs(1 ,1 ,1); if(!f) { cout << -1; } return 0; }