60pts求救
查看原帖
60pts求救
726902
bcbgszyzh楼主2024/2/23 13:40
#include<bits/stdc++.h>
using namespace std;
int cnt=0;
int n;
void dfs(stack<int>op,stack<int>st){
    if(op.empty()&&st.empty()){
        ++cnt;
    }
    if(!op.empty()){
        int f=op.top();
        op.pop();
        st.push(f);
        dfs(op,st);
        st.pop();
        op.push(f);
    }
    if(!st.empty()){
        int f=st.top();
        st.pop();
        dfs(op,st);
        st.push(f);
    }
}
int main(){
    scanf("%d",&n);
    stack<int>op,st;
    for(int i=n;i>=1;--i){
        op.push(i);
    }
    dfs(op,st);
    printf("%d",cnt);
    return 0;
}
2024/2/23 13:40
加载中...