Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
108604 周歆童 全排列问题 C++ 通过 100 19 MS 252 KB 474 2023-11-04 09:06:34

Tests(5/5):


#include<bits/stdc++.h> using namespace std; int n,ans,a[10]; bool b[10]; void dfs(int depth){ if(depth>n){ for(int i=1;i<=n;i++){ printf("%d",a[i]); } printf("\n"); ans++; return; } for(int i=1;i<=n;i++){ if(!b[i]){ b[i]=1; a[depth]=i; dfs(depth+1); b[i]=0; } } return; } int main(){ //freopen("permutation.in","r",stdin); //freopen("permutation.out","w",stdout); cin>>n; dfs(1); cout<<ans; return 0; }


测评信息: