Pagini recente » Cod sursa (job #2595190) | Cod sursa (job #695285) | Cod sursa (job #1559661) | Cod sursa (job #2831517) | Cod sursa (job #491747)
Cod sursa(job #491747)
#include "stdio.h"
using namespace std;
int n,p;
int st[1000010];
void initializare(int k,int v[])
{
v[k]=0;
}
void succesor(bool &as,int st[],int k)
{
as=false;
if(st[k]<n)
{
st[k]++;
as=true;
}
}
void valid(bool &ev,int st[],int k)
{
ev=true;
for(int i=0;i<k;i++)
if(st[k]==st[i])
ev=false;
if(k>1)
if(st[k-1]>st[k])
ev=false;
}
int solutie(int k)
{
return(k==p);
}
int main()
{
FILE* f=fopen("submultimi.in","r");
FILE* g=fopen("submultimi.out","w");
bool ev,as;
int k,i;
fscanf(f,"%d",&n);
for(int m=1;m<=n;m++)
{
p=m;
k=1;
initializare(k,st);
while(k>0)
{
do
{
succesor(as,st,k);
if(as) valid(ev,st,k);
}
while(!( !as || (as && ev)));
if(as)
{
if(solutie(k))
{
for(i=1;i<=p;i++)
fprintf(g,"%d ",st[i]);
fprintf(g,"\n");
}
else
{
k++;
initializare(k,st);
}
}
else
k--;
}
}
return 0;
}