public static Modular Pow(Modular a, int n) { switch (n) { case 0: return(1); case 1: return(a); default: var p = Pow(a, n / 2); return(p * p * Pow(a, n % 2)); } }
public void Solve() { @in(out H, out W, out K); int fall = 0; int p = (int)Math.Pow(2, W - 1); // 全探索 for (int i = 0; i < p; i++) { bool invalidate = false; var n = i; bool before = false; for (int j = 0; j < W - 1; j++) { int bit = n % 2; n = n >> 1; if (bit != 0 && before) { invalidate = true; break; } before = bit != 0; } if (invalidate) { continue; } fall++; } Modular[][] dp = new Modular[H + 1][]; dp[0] = new Modular[W]; dp[0][0] = 1; for (int i = 1; i < W; i++) { dp[0][i] = 0; } for (int i = 1; i <= H; i++) { dp[i] = new Modular[W]; for (int j = 0; j < W; j++) { dp[i][j] = 0; } for (int j = 0; j < W; j++) { dp[i][j] = dp[i - 1][j]; if (j > 0) { dp[i][j] = dp[i][j] + dp[i - 1][j - 1]; } if (j < W - 1) { dp[i][j] = dp[i][j] + dp[i - 1][j + 1]; } } } Console.WriteLine((int)dp[H][K - 1]); }