其他分享
首页 > 其他分享> > 题解 打地鼠

题解 打地鼠

作者:互联网

传送门

二维前缀和,没了
讲个笑话,离考试结束还有5min我检查代码时发现我忘了我刚写过这么个题了

Code:

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 2010
#define ll long long 
//#define int long long 

inline int read() {
	int ans=0, f=1; char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
	while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
	return ans*f;
}

int n, k;
int mp[N][N], sum[N][N];
char t[N];

namespace force{
	int ans;
	void solve() {
		for (int i=1; i<=n; ++i)
			for (int j=1; j<=n; ++j)
				sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+mp[i][j];
		for (int i=k; i<=n; ++i)
			for (int j=k; j<=n; ++j)
				ans = max(ans, sum[i][j]-sum[i-k][j]-sum[i][j-k]+sum[i-k][j-k]);
		printf("%d\n", ans);
		exit(0);
	}
}

signed main()
{
	n=read(); k=read();
	for (int i=1; i<=n; ++i) {
		scanf("%s", t+1);
		for (int j=1; j<=n; ++j)
			mp[i][j]=t[j]-'0';
	}
	force::solve();
	
	return 0;
}

标签:int,题解,long,地鼠,ans,isdigit,getchar,define
来源: https://www.cnblogs.com/narration/p/15142540.html