Cod sursa(job #31011)

Utilizator therain3rVlad Dumitrescu therain3r Data 15 martie 2007 13:20:31
Problema Pavare2 Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <stdio.h>
#include <string.h>

FILE *f=freopen("pavare2.in","r",stdin), *g=freopen("pavare2.out","w",stdout);

int i,j,x[101],nr,N,A,B,K,safe[2],help[2][101],stuff[101];


int test(int i)
{
 if (help[0][i]<=A && help[1][i]<=B) return 1;
 return 0;
}

void af()
{

 for(int i=1;i<=N;i++)
 {
// printf("%d ",x[i]);
 stuff[i]=x[i];
 }

 //printf("\n");
}

void back()
{
 i=1;
 while (i)
 {
  x[i]++;
  if (x[i]>1)
    {
     x[i]=-1;
     help[1][i]=0;
     i--;
    }
  else
  {
   help[x[i]][i]=help[x[i]][i-1]+1;
   if (x[i]==1) help[0][i]=0;



   if (test(i))
    if (i==N)
    {
     nr++;
     if(K==nr)af();
    }
    else i++;
  }
 }
}

int main()
{
 scanf("%d %d %d",&N,&A,&B);
 scanf("%d",&K);

 memset(x,-1,sizeof(x));


 back();

 printf("%d\n",nr);
 for (i=1;i<=N;i++) printf("%d",stuff[i]);
 return 0;
}