Cod sursa(job #30681)

Utilizator MarcvsHdrMihai Leonte MarcvsHdr Data 14 martie 2007 21:10:47
Problema Pavare2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
# include <stdio.h>

int n,a,b;long long int k;
const int MAXN=100;

long long c[MAXN+1][2];

void citire()
{
FILE *f=fopen("pavare2.in","r");
fscanf(f,"%d%d%d%lld",&n,&a,&b,&k);
fclose(f);
}

int min (int a, int b) {if (a>b) return b; return a;}

void calculeaza()
{
int i,j;
c[0][1]=c[0][0]=1;
for (i=1;i<=n;i++)
	{
	for (j=1;j<=min(a,i);j++) c[i][0]+=c[i-j][1];
	for (j=1;j<=min(b,i);j++) c[i][1]+=c[i-j][0];
	}
}

void scrie()
{
FILE *g=fopen("pavare2.out","w");
fprintf(g,"%lld\n",c[n][1]+c[n][0]);
/// scrie solutia
int x=n;
while (k)
	if (c[x][0]>k) {fprintf(g,"0");x--;}
	else {fprintf(g,"1");k-=c[x][0];x--;}
fprintf(g,"\n");
fcloseall();
}

int main()
{
citire();
calculeaza();
scrie();
return 0;
}