二维前缀和

```

#include<bits/stdc++.h>
using namespace std;
int n,m,K,cnt;
int a[510][510],f[510][510];
int main()
{
cin>>n>>m>>K;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
f[i][j]=f[i][j-1]+f[i-1][j]-f[i-1][j-1]+a[i][j];
}
}
for(int x1=1;x1<=n;x1++)
{
for(int y1=1;y1<=m;y1++)
{
for(int x2=x1;x2<=n;x2++)
{
for(int y2=y1;y2<=m;y2++)
{
int ans=f[x2][y2]-f[x1-1][y2]-f[x2][y1-1]+f[x1-1][y1-1];
if(ans<=K)
{
cnt++;
}
}
}
}
}
cout<<cnt;
return 0;
}

```

 

posted @ 2022-11-15 10:22  Herkaii  阅读(28)  评论(0)    收藏  举报