思路:



#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1010;
int n,m,k,a[N][N];
int check(int x1,int y1,int x2,int y2){
    return a[x2][y2] - a[x1-1][y2] - a[x2][y1-1] + a[x1-1][y1-1];
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            char ch;scanf(" %c",&ch);
            a[i][j] = ch - '0';
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            a[i][j] += a[i-1][j] + a[i][j-1] - a[i-1][j-1];
        }
    }
    int ans = 0;
    for(int i = 1;i+k-1 <= n;i++){
        for(int j = 1;j+k-1 <= m;j++){
            if(check(i,j,i+k-1,j+k-1)){
                ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}