剪枝YYDS
2024-09-29 21:32:28
发布于:广东
5阅读
0回复
0点赞
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int n,r;
void DFS(int i,vector<int> z){
if(i == r){
for(int j = 0;j < z.size();j ++){
cout << setw(3) << z[j];
}
cout << endl;
return;
}
int tmp2;
if(z.size() == 0){
tmp2 = 0;
} else {
tmp2 = z[z.size() - 1];
}
for(int j = tmp2 + 1;j <= tmp2 + (n - tmp2) - (r - i) + 1;j ++){
vector<int> tmp = z;
tmp.push_back(j);
DFS(i + 1,tmp);
}
}
int main(){
cin >> n >> r;
DFS(0,{});
return 0;
}
这里空空如也
有帮助,赞一个