提交时间:2024-02-23 22:06:24

运行 ID: 132573

#include<bits/stdc++.h> using namespace std; int a,b,cnt=0; bool ss=1; int x[100001]; int se(int m,int n){ if(n>1&&m<b){ cnt++; x[cnt]=1; se(m+1,n-2); cnt--; } if(n>0&&m<b-1){ cnt++; x[cnt]=2; se(m+2,n-1); cnt--; } if(n<a&&m<b-1){ cnt++; x[cnt]=3; se(m+2,n+1); cnt--; } if(n<a-1&&m<b){ cnt++; x[cnt]=4; se(m+1,n+2); cnt--; } if(m==a&&n==b&&ss){ for(int i=1;i<=cnt;i++) cout<<x[i]<<" "; ss=0; } } int main(){ cin>>a>>b; se(1,1); }