题目链接:https://codeforces.com/problemset/problem/1081/C
直接dp
考虑第 i 块砖,可以与左边相同,也可以不同
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 2010;
const int mod = 998244353;
int n,m,k;
int dp[maxn][maxn]; // 到第 i 块砖,有 k 块砖颜色与左边不同
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
n = read(), m = read(), k = read();
for(int i=1;i<=n;++i){
dp[i][0]=m;
for(int j=1;j<=k;++j){
dp[i][j] = (dp[i-1][j] + 1ll * dp[i-1][j-1] * (m - 1) % mod) % mod;
}
}
printf("%d ",dp[n][k]);
return 0;
}