Cod sursa(job #2516270)
Utilizator | bety bety bety | Data | 30 decembrie 2019 20:58:13 |
---|---|---|---|
Problema | Combinari | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
using namespace std;
ifstream in("combinari.in");
ofstream out("combinari.out");
int n,k;
void generare(string s,int poz,int nr)
{
if(poz==n+1 and nr==k)
{
for(int i=1;i<=n;++i)
if(s[i]=='1')
out<<i<<" ";
out<<endl;
}
else if(poz<=n and nr<=k)
{
s[poz]='1';
generare(s,poz+1,nr+1);
s[poz]='0';
generare(s,poz+1,nr);
}
}
string s="000000000000000000000";
int main()
{
ios_base::sync_with_stdio(false);
in.tie(0),out.tie(0);
in>>n>>k;
generare(s,1,0);
return 0;
}