Pagini recente » Cod sursa (job #45051) | Cod sursa (job #2235388) | Cod sursa (job #2959960) | Cod sursa (job #3187953) | Cod sursa (job #1104675)
#include <cstdio>
using namespace std;
int st[20],n,k,p;
bool as,ev,stop;
void succ(bool &as)
{
if (st[k]<n-p+k)
{
st[k]=st[k]+1;
as=true;
}
else as=false;
}
void valid(bool &ev)
{
int i;
ev=1;
if (k>1 && st[k]<st[k-1]) ev=false;
else
for(i=1;i<=k-1;++i)
if (st[i]==st[k]) {ev=false;break;}
}
void tipareste()
{
int i;
for(i=1;i<=k;++i) printf("%d ",st[i]);printf("\n");
}
int main()
{
freopen("submultimi.in","r",stdin);
scanf("%d",&n);
freopen("submultimi.out","w",stdout);
for(p=1;p<=n;++p)
{
k=1;
st[1]=0;
while(k>0)
{
stop=false;
do
{
succ(as);
if (as) valid(ev);
if (!as || (as && ev)) stop=true;
}
while(!stop);
if (as)
{
if (k==p) tipareste();
else {++k;st[k]=0;}
}
else --k;
}
}
return 0;
}