【算法分类】【搜索】【DFS】枚举所有子集

    xiaoxiao2025-10-26  5

    //【算法分类】【搜索】【DFS】枚举所有子集 #include <cstdio> using namespace std; const int MAXSIZE = 10005; int a[MAXSIZE],n; bool used[MAXSIZE]; void dfs(int dep) { if (dep>n) { for(int i=1; i<=n; i++) if (used[i]) printf("%d ",a[i]); printf("\n"); return; } used[dep]=false; dfs(dep+1); used[dep]=true; dfs(dep+1); } int main() { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); dfs(1); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1303534.html
    最新回复(0)