1 solutions

  • 0
    @ 2022-4-12 22:06:34
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int N=15;
    int a[N],p[N];
    bool st[N];//判重,不能填一样的数字 
    int n;
    void dfs(int u)
    {
    	if(u>n)
    	{
    		for(int i=1;i<=n;i++)//p数组是填数的 
    			cout<<p[i]<<" ";
    		cout<<endl;
    		return ;
    	}
    	for(int i=1;i<=n;i++)
    	{
    		if(!st[a[i]])
    		{
    			p[u]=a[i];
    			st[a[i]]=true;
    			dfs(u+1);
    			st[a[i]]=false;
    		}
    	}
    }
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++) cin>>a[i];
    	sort(a+ 1,a+n+1);
    	dfs(1);
    	return 0;
    }
    
    • 1

    Information

    ID
    1022
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    6
    Tags
    # Submissions
    66
    Accepted
    21
    Uploaded By