¶
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;
}










