文章
24
粉丝
27
获赞
117
访问
4.4k
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c, n, k, x, y, sum = 0;
cin >> r >> c >> n >> k;
vector<vector<int>> a(r, vector<int>(c, 0));
vector<vector<int>> dp(r + 1, vector<int>(c + 1, 0));
// 读取坐标并填充矩阵
for (int i = 0; i < n; i++) {
cin >> x >> y;
a[x - 1][y - 1] = 1;
}
// 构建二维前缀和数组
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i - 1][j - 1];
}
}
// 枚举所有行范围(top, bottom),优化为滑动窗口,不优化也行4个for循环,O(r²c²)时间复杂罢了也能ac
for (int top = 1; top <= r; top++)...
登录后发布评论
暂无评论,来抢沙发