int NC(int p, int n)
{
if( p == 1 )
return 1;
else {
int sum = 0;
for(int i = 0; i <= n; ++i)
sum += NC(p - 1, n - i);
return sum;
}
}
(1, 1, 1, 1, 1, 1, 1, 1, 1)
(1, 2, 3, 4, 5, 6, 7, 8, 9)
(1, 3, 6, 10, 15, 21, 28, 36, 45)
(1, 4, 10, 20, 35, 56, 84, 120, 165)
(1, 5, 15, 35, 70, 126, 210, 330, 495)
(1, 6, 21, 56, 126, 252, 462, 792, 1287)
(1, 7, 28, 84, 210, 462, 924, 1716, 3003)
(1, 8, 36, 120, 330, 792, 1716, 3432, 6435)
(1, 9, 45, 165, 495, 1287, 3003, 6435, 12870)
(1, 10, 55, 220, 715, 2002, 5005, 11440, 24310)
(1, 11, 66, 286, 1001, 3003, 8008, 19448, 43758)
(1, 12, 78, 364, 1365, 4368, 12376, 31824, 75582)
(1, 13, 91, 455, 1820, 6188, 18564, 50388, 125970)
(1, 14, 105, 560, 2380, 8568, 27132, 77520, 203490)
// ix ~ 0 に n 個の石を置く場合の数を数える
// ただし ix 位置には1個以上石を置くものとする
int nPermutation1Color(int ix, int n)
{
if( !ix )
return 1;
else {
int sum = 0;
for(int i = 1; i <= n; ++i)
sum += NC(ix, n - i);
return sum;
}
}
// ランニング状態の状態数を返す
template<int NP, int NS>
int nPermutationRunning()
{
int sum = 0;
for(int bt = 1; bt < NP; ++bt) {
int n = nPermutation1Color(bt, NS); // 最後尾が bt の時の状態数
for(int wt = 1; wt <= NP - bt; ++wt) {
sum += n * nPermutation1Color(wt, NS);
}
}
return sum;
}