92. 递归实现指数型枚举

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
int n;
int a[16],vis[16];
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ )
a[i]=i+1;
int state;
cout<<endl;
for(state=1;state<(1<<n);state++)
{
for (int j = 0; j <n; j ++ )
{
if((state>>j)&1)
printf("%d ",a[j]);
}
cout << endl;
}
return 0;
}
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022-2024 CPY
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信