Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- ifstream fin("combinari.in");
- ofstream fout("combinari.out");
- int val_min=1,val_max = 2,n,k;
- vector<int>sol;
- bool valid()
- {
- for(auto i = sol.begin(); i != sol.end()-1 ; i++)
- {
- if(*i >= sol.back())
- {
- return 0;
- }
- }
- return 1;
- }
- bool solutie()
- {
- return sol.size() == k;
- }
- void prelucrare_sol()
- {
- for(const auto& it : sol)
- {
- //cout<<it<<' ';
- fout<<it<<' ';
- }
- //cout<<'\n';
- fout<<'\n';
- }
- void backt()
- {
- for(int i=val_min; i<=val_max; i++)
- {
- sol.push_back(i); ///solutie candidata
- if(valid())
- {
- if(solutie())
- {
- prelucrare_sol();
- }
- else
- {
- backt();
- }
- }
- sol.pop_back();
- }
- }
- int main()
- {
- //cin>>n>>k;
- fin>>n>>k;
- val_max=n;
- backt();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement