1 条题解

  • 0
    @ 2024-1-26 15:45:01

    递归实现指数型枚举

    #include <queue>
    #include <math.h>
    #include <stack>
    #include <vector>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include<cstring>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 1e2 + 10;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    int n , a[N]; 
    void f(int pre ,int step)
    {
    	if(step > 0)
    	{
    		for(int i = 0 ;i < step ; i++)
    		{
    			cout << a[i] <<" ";
    		}
    		cout << endl ;
    	}
    	for(int i = pre + 1 ;i <= n ; i++ )
    	{
    		a[step] = i ;
    		f(i , step + 1);
    	}
    }
    int main()
    {
    	cin >> n ;
    	f( 0 , 0 );
    	return 0;
    }
    
    • 1

    信息

    ID
    5
    时间
    1000ms
    内存
    128MiB
    难度
    4
    标签
    递交数
    568
    已通过
    261
    上传者