Cod sursa(job #137561)

Utilizator VmanDuta Vlad Vman Data 17 februarie 2008 12:40:46
Problema Arbori Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 4, Clasele 11-12 Marime 1.04 kb
#include <stdio.h>
#include <string.h>

int N,M,K,G,i;
long long A[100];
int st[100];

void solutie()
{
 long long S=1;
 int j;
 for (j=1;j<=G;++j)
     S*=A[st[j]];
 A[i]+=S;
}

void partitii(int S,int nr,int k)
{
 int i;
 if (k==0) if (nr==S) solutie();
    else return;
 if (k==G)
    for (i=1;i<=S;++i)
        {
         st[k]=i;
         partitii(S,nr+i,k-1);
        }
    else
    for (i=st[k+1];i<=S;++i)
        if (nr+i<=S)
        {
         st[k]=i;
         partitii(S,nr+i,k-1);
        }
        else return;
}

void compute()
{
 A[1]=1;
 for (i=2;i<N;++i)
     {
      G=K-1;
      if (G==0) G+=M;
      while (G<i)
            {
             partitii(i-1,0,G);
             G+=M;
            }
     }
}

int main()
{
 freopen("arbori.in","r",stdin);
 scanf("%d %d %d",&N,&M,&K);
 compute();
 G=K;i=N;
 if (G==0) G+=M;
 while (G<N)
       {
        partitii(N-1,0,G);
        G+=M;
       }
 freopen("arbori.out","w",stdout);
 printf("%d",A[N]);
 fclose(stdout);
 return 0;
}