F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Rikka with Seam

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 429    Accepted Submission(s): 201


Problem Description
Seam carving is a novel algorithm for resizing images while maintaining as much information as possible from the source image.

Now, Rikka is going to use seam carving method to deal with an $n \times m$ black and white picture. We can abstract this picture into an $n \times m$ 01 matrix $A$.

A $K$-seam of this picture is an integer sequence $a$ which satisfies the following conditions:
1. $|a| = n$, $a_i \in [1, m]$.
2. $|a_i - a_{i+1}| \leq K$, $\forall i \in [1,n)$.

After choosing a $K$-seam $a$, Rikka reduces the size of the picture by deleting pixels $(i,a_i)$, and then she gets a matrix $A'$ of size $n \times (m - 1)$.

For example, if the chosen seam is $[1,2,3]$ and the picture is \begin{align*} \begin{bmatrix} 1 &0 &0 \\ 1& 1& 1 \\ 0 & 0& 0\end{bmatrix}\end{align*} the result matrix will be \begin{align*} \begin{bmatrix} 0 &0 \\ 1& 1 \\ 0 & 0\end{bmatrix}\end{align*}

Rikka finds that deleting different seams may get the same result. In the previous example, seam $[1,2,3],[1,2,1],[1,2,2],[1,1,1]$ are equivalent.

Now Rikka wants to calculate the number of different matrixes she can get by deleting exactly one $K$-seam.
 

Input
The first line contains a single integer $t(1 \leq t \leq 10^3)$, the numebr of testcases.

For each testcase, the first line contains three numbers $n,m,K(2 \leq n,m \leq 2 \times 10^3, 1\leq K \leq m)$.

Then $n$ lines follow, each line contains a 01 string of length $m$ which describes one row of the matrix.

The input guarantees that there are at most $5$ testcases with $\max (n,m) > 300$.
 

Output
For each testcase, output a single line with a single number, the answer modulo $998244353$.
 

Sample Input
3 2 2 1 00 10 5 5 1 00100 10101 00100 01000 11101 5 5 2 00100 10101 00100 01000 11101
 

Sample Output
2 70 199
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 15:24:18, Gzip enabled