¶
1)) 기계 2 깊 2 개 = (2^(2+1) - 1)/(2-1) = 7개
2)) 1 7개 1개 3개 기계 2 게 3개 3개 .
combination( , /기계) .
combination(6, 6/2) 고 게 2! 곱.
깊 1 경 = 기계! * combination( , 뺸 /기계)
과 깊 2 깊 1 각 공 .
¶
~cpp
#include <iostream>
#include <cmath>
#include "BigInteger.h"
using BigMath::BigInteger;
int depth, level, nodeNum, temp, templevel, tempdepth, select, i;
BigInteger labelingNum;
BigInteger factorial[3300];
void InitFactorial()
{
factorial[1] = 1;
for(i=2; i<3300; i++)
factorial[i] = factorial[i-1] * i;
}
BigInteger combination(int a, int b)
{
if(a==b)
return 1;
return factorial[a]/(factorial[b]*factorial[a-b]);
}
BigInteger getCompleteTreeLabeling(int l, int d)
{
labelingNum=1;
tempdepth=1;
if(l==1)
return 1;
nodeNum = (pow(l, d+1)-1)/(l-1);
nodeNum--;
while(true)
{
if(nodeNum==0)
return labelingNum/l;
select = nodeNum/l;
labelingNum = labelingNum * factorial[l] * combination(nodeNum, select);
nodeNum = select-1;
tempdepth++;
}
}
int main()
{
InitFactorial();
while(cin>>level>>depth)
cout << getCompleteTreeLabeling(level, depth) << endl;
return 0;
}










