bzoj1 218 激光炸弹(二位前缀和)
作者:互联网
思路:二维前缀和
#include
using namespace std;
const int N = 5010;
int dp[N][N];
int n, r;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif //ONLINE_JUDGE
int a, b, c, ans;
while(~scanf("%d%d", &n, &r)){
for(int i = 1; i <= n; i++){
ans = 0;
scanf("%d%d%d", &a, &b, &c);
dp[a + 1][b + 1] = c;
}
for(int i = 1; i <= 5001; i++){
for(int j = 1; j <= 5001; j++){
dp[i][j] += dp[i - 1][j];
}
}
for(int i = 1; i <= 5001; i++){
for(int j = 1; j <= 5001; j++){
dp[i][j] += dp[i][j - 1];
}
}
for(int i = r; i <= 5001; i++){
for(int j = r; j <= 5001; j++){
ans = max(ans, dp[i][j] - dp[i - r][j] - dp[i][j - r] + dp[i - r][j - r]);
}
}
printf("%d\n", ans);
}
return 0;
}
标签:bzoj1,int,218,ONLINE,JUDGE,前缀 来源: https://www.cnblogs.com/kun-/p/10585449.html