帮我去掉注释:#include <iostream>#include <algorithm>using namespace std;int n, r;int nums[20], comb[20];void dfs(int cur, int cnt) { if (cnt == r) { // 选出r个数 for (int i = 0; i < r; i++) { cout << comb[i] << " "; } cout << endl; return; } if (cur == n) return; // 所有数都已经遍历完 comb[cnt] = nums[cur]; // 选当前数 dfs(cur+1, cnt+1); dfs(cur+1, cnt); // 不选当前数}int main() { cin >> n >> r; for (int i = 0; i < n; i++) { cin >> nums[i]; } sort(nums, nums+n); // 排序 dfs(0, 0); return 0;}
时间: 2024-03-15 15:42:42 浏览: 71
把C/C++中的注释去掉
#include <iostream>
#include <algorithm>
using namespace std;
int n, r;
int nums[20], comb[20];
void dfs(int cur, int cnt) {
if (cnt == r) {
for (int i = 0; i < r; i++) {
cout << comb[i] << " ";
}
cout << endl;
return;
}
if (cur == n) return;
comb[cnt] = nums[cur];
dfs(cur+1, cnt+1);
dfs(cur+1, cnt);
}
int main() {
cin >> n >> r;
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
sort(nums, nums+n);
dfs(0, 0);
return 0;
}
阅读全文