给你n个方格排成一行,有m种颜色,然后要把这n个方格分成k+1段,每段涂不同的颜色,问有多少种方法。
排列组合问题,首先要在n-1个位置里面选出k个位置当作段与段的分割点,然后每段涂的时候有m*(m-1)^k种,二者相乘即使答案。
要注意的是计算组合数的时候也要取mod,因为组合数的增加也是很快的。
还有要上快速幂计算
所以C(n-1,k)m(m-1)^k。注意取模。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int maxn=2010;
const LL mod=998244353;
LL jie[maxn],ni[maxn];
LL fast_pow(LL a,LL n)
{
LL sum=1;
while(n)
{
if(n&1) sum=sum*a%mod;
a=a*a%mod;
n/=2;
}
return sum;
}
void init