2 solutions

  • 0
    @ 2025-12-8 22:30:34
    #include <bits/stdc++.h>
    using namespace std;
    int n,arr[30],m;
    bool b[30];
    void dfs(int x,int y)
    {
    	if(x==m+1)
    	{
    		for(int i=1;i<=m;i++)
    		{
    			cout<<arr[i]<<" ";
    		}
    		cout<<"\n";
    		return;
    	}
    	for(int j=y;j<=n;j++)
    	{
    		if(!b[j])
    		{
    			b[j]=true;
    			arr[x]=j;
    			dfs(x+1,j+1);
    			b[j]=false;
    		}
    	}
    	return;
    }
    int main()
    {
    	cin>>m>>n;
    	dfs(1,1);
    	return 0;
    }
    

    Information

    ID
    2752
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    6
    Accepted
    4
    Uploaded By