代码如下 :
#include<iostream>
using namespace std;
int S(int count, int color)
{
int c;
if (count == 1)
c = color;
else if (count == 2)
c = color * (color - 1);
else if (count == 3)
c = color * (color - 1) * (color - 2);
else if (count > 3)
c = S(count - 1, color) * (color - 2) + S(count - 2, color) * (color - 1);
return c;
}
int main()
{
int m, n, p;
cout << "请分别输入扇形数和颜色数:";
cin >> m >> n;
p = S(m, n);
cout << "有" << p << "种方案";
return 0;
}
解释如下 :
S函数是一个递归函数,用于计算染色方案数。
函数接受两个参数:
count
:表示扇形的数量。
color
&#