import java.io.IOException; import java.util.Arrays; import java.util.Scanner; public class Main { static int n, m, k; static int MOD = 998244353; static long m1 = 1l; //1/m (mod MOD的值 public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); m1 = ksm(m, MOD - 2); long[] dp = new long[n + 1]; dp[0] = 1; for (int i = 1; i <= k; i++) { long[] nextdp = new long[n + 1]; // nextdp = Arrays.copyOf(dp, dp.length); nextdp[n] = dp[n]; for (int x = 0; x < n; x++) { for (int di = 1; di <= m; di++) { int newx = x+di; if (x + di >= n) { newx = n - (newx - n); } nextdp[newx] = nextdp[newx] + ((dp[x] * m1) % MOD); nextdp[newx] %= MOD; } } dp = Arrays.copyOf(nextdp, nextdp.length); } System.out.println(dp[n]); } public static long ksm(long a, int p) { if (p == 0) { return 1l; } if (p == 1) { return a; } long tmp = ksm(a, p / 2); long ans = tmp * tmp; ans %= MOD; if (p % 2 == 1) { ans = ans * a; ans %= MOD; } return ans; } }
标签:atcoder,long,Sugoroku,newx,static,ans,nextdp,293,MOD From: https://www.cnblogs.com/fishcanfly/p/16842798.html