题解:三层循环,连找n个0数量加一。
#include <stdio.h>
#include <string.h>
const int N = 105;
int m[N][N], row, col, ans, n;
int main() {
int t;
scanf("%d", &t);
while (t--) {
ans = 0;
scanf("%d%d%d", &row, &col, &n);
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
scanf("%d", &m[i][j]);
for (int i = 0; i < row; i++)
for (int j = 0; j < (col - n + 1); j++) {
int temp = 0;
for (int k = 0; k < n; k++)
if (m[i][j + k] == 0)
temp++;
if (temp == n)
ans++;
}
printf("%d\n", ans);
}
return 0;
}