#include #include const int Mod = 998244353; int main() { int i, j, H, W, K; char **c, **c_tmp; scanf("%d %d %d", &H, &W, &K); c_tmp = (char**)malloc(sizeof(char*) * (H + 2)); for (i = 1; i <= H; i++) { c_tmp[i] = (char*)malloc(sizeof(char) * (W + 2)); scanf("%s", &(c_tmp[i][1])); } if (H <= W) { W += K; c = (char**)malloc(sizeof(char*) * (H + 2)); for (i = 0; i <= H + 1; i++) { c[i] = (char*)malloc(sizeof(char) * (W + 2)); for (j = 0; j <= W + 1; j++) c[i][j] = 0; } for (i = 1; i <= H; i++) for (j = K + 1; j <= W; j++) c[i][j] = c_tmp[i][j-K]; } else { H ^= W; W ^= H; H ^= W; W += K; c = (char**)malloc(sizeof(char*) * (H + 2)); for (i = 0; i <= H + 1; i++) { c[i] = (char*)malloc(sizeof(char) * (W + 2)); for (j = 0; j <= W + 1; j++) c[i][j] = 0; } for (i = 1; i <= H; i++) for (j = K + 1; j <= W; j++) c[i][j] = c_tmp[j-K][i]; } int tmp, **dp, **dp_sum_add, **dp_sum_sub; dp = (int**)malloc(sizeof(int*) * (H + 2)); dp_sum_add = (int**)malloc(sizeof(int*) * (H + 2)); dp_sum_sub = (int**)malloc(sizeof(int*) * (H + 2)); for (i = 0; i <= H + 1; i++) { dp[i] = (int*)malloc(sizeof(int) * (W + 2)); dp_sum_add[i] = (int*)malloc(sizeof(int) * (W + 2)); dp_sum_sub[i] = (int*)malloc(sizeof(int) * (W + 2)); } for (i = 0; i <= H + 1; i++) { for (j = 0; j <= W + 1; j++) { dp[i][j] = 0; dp_sum_add[i][j] = 0; dp_sum_sub[i][j] = 0; } } dp[1][K+1] = 1; dp_sum_add[1][K+1] = 1; dp_sum_sub[1][K+1] = 1; for (i = 1, j = K + 2, tmp = 1; 1; j++) { if (j > W) { i++; if (i > H) break; j = 0; tmp = 0; } tmp += dp_sum_add[i-1][j]; if (j >= K + 1) tmp -= dp_sum_sub[i][j-K-1]; if (tmp >= Mod) tmp -= Mod; else if (tmp < 0) tmp += Mod; if (c[i][j] == '.') dp[i][j] = tmp; else dp[i][j] = 0; dp_sum_add[i][j] = dp_sum_add[i-1][j] + dp[i][j]; if (i - K >= 1) dp_sum_add[i][j] -= dp[i-K][j]; if (dp_sum_add[i][j] >= Mod) dp_sum_add[i][j] -= Mod; else if (dp_sum_add[i][j] < 0) dp_sum_add[i][j] += Mod; dp_sum_sub[i][j] = dp_sum_sub[i-1][j+1] + dp[i][j]; if (i - K - 1 >= 1 && j + K + 1 <= W) dp_sum_sub[i][j] -= dp[i-K-1][j+K+1]; if (dp_sum_sub[i][j] >= Mod) dp_sum_sub[i][j] -= Mod; else if (dp_sum_sub[i][j] < 0) dp_sum_sub[i][j] += Mod; tmp += dp[i][j]; if (tmp >= Mod) tmp -= Mod; } printf("%d\n", dp[H][W]); fflush(stdout); return 0; }