AcWing 1572. 递归实现指数型枚举 II
原题链接
简单
作者:
skysee
,
2020-04-04 18:26:25
,
所有人可见
,
阅读 1238
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 20;
int n;
int d[N];
void calc(int x, vector<int>& result) {
for (int i = 0; i < result.size(); i++) {
printf("%d ", result[i]);
}
puts("");
for (int i = x; i < n; i++) {
if (i != x && d[i] == d[i-1]) continue;
result.push_back(d[i]);
calc(i+1, result);
result.pop_back();
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> d[i];
sort(d, d+n);
vector<int> result;
calc(0, result);
}
精致的递归树,画一画。思路就出来了。不过,按照样例画的递归树,和你的答案不一致呀。223333