Pagini recente » Cod sursa (job #3141429) | Cod sursa (job #2588037) | Cod sursa (job #2641890) | Cod sursa (job #2300082) | Cod sursa (job #1652248)
#include <cstring>
#include <fstream>
#include <algorithm>
using namespace std;
int N, M, K;
long long D[92][12][92];
long long getR(int nodes, int modul, int prev)
{
if(nodes == 1 && modul == 0) return 1;
if(nodes == 1) return 0;
if(prev == 0) return 0;
long long& now = D[nodes][modul][prev];
if(now != -1) return now;
now = getR(nodes, modul, prev - 1);
long long COMB = getR(prev, (M + K - 1) % M, prev - 1), up = COMB, down = 1;
for(int act = 1; act * prev < nodes; ++act)
{
now += getR(nodes - prev * act, (M * 100 + modul - act) % M, prev - 1) * (prev == 1 ? 1 : COMB);
++up, ++down;
COMB = COMB*up / down;
}
return now;
}
int main()
{
ifstream fin("arbori.in");
ofstream fout("arbori.out");
memset(D, -1, sizeof(D));
fin >> N >> M >> K;
fout << getR(N, K, N) << '\n';
fin.close();
fout.close();
}