Cod sursa(job #3339710)

Utilizator stefan_dore_Stefan Dore stefan_dore_ Data 9 februarie 2026 16:20:06
Problema Arbori Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("arbori.in");
ofstream g("arbori.out");

const int NMAX=90,
          MMAX=10,
          KMAX=90;
int N, M, K;
long long D[NMAX+1][MMAX+1][KMAX+1];

int main(){
    f >> N >> M >> K;

    for(int i=0; i<N; i++)
        D[1][0][i]=1;

    for(int i=2; i<=N; i++)
        D[i][(i-1)%M][1]=1;

    for(int i=2;i<=N; i++)
        for(int k=2; k<=N-1; k++)
            for(int j=0; j<=M-1; j++)
            {
                long long comb=1;
                //
                for(int x=0; x*k<i; x++) {
                    D[i][j][k] += comb * D[i-x*k][(j-x+(M<<10))%M][k-1];
                    comb = comb * (D[k][(K-1+M)%M][k-1] + x) / (x + 1);
                }
            }
    //
    g << D[N][K][N-1];
    //
    f.close();
    g.close();
    return 0;
}