3 solutions

  • 0
    @ 2025-12-22 14:47:58
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	vector<int> a;
    	for(int i=0;i<n;i++) a.push_back(0);
    	for(int i=0;i<m-n;i++) a.push_back(1);
    	do{
    		for(int i=0;i<m;i++) //枚举每个位置
    		{
    			if(a[i]==0) cout<<i+1<<" "; //选择当前数
    		}
    		cout<<endl;
    	}while(next_permutation(a.begin(),a.end())); //产生下一个全排列
    	return 0;
    }
    
    • 0
      @ 2025-12-8 22:31:37

      A1753 组合型枚举

      和这题一样

      • 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;
        }
        
        • 1

        Information

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