1218: [HNOI2003] laser bombs
Description
A novel laser bombs that can destroy all of the length of one side of the square R of the target. There are map n (N <= 10000) target, an integer Xi, Yi (its value in [0,5000]) indicates the position of the target on a map, each has a certain value. Laser bombs served by satellite positioning, but it has a disadvantage that its explosion range, i.e., the side length of the sides of the square must R and x, y-axis. If the target is located on the edge of the square blasting, the target will not be destroyed.
Input
The first line of the input file and the integer n a positive integer R, the next n lines each have three positive integers, respectively, xi, yi, vi
Output
The output file is only a positive integer representing up to blow up a bomb on a map total value of the number of goals (results not more than 32,767).
Sample Input
2 1
0 0 1
1 1 1
Sample Output
1
Ideas: a matrix product refresh most value like two-dimensional prefix and enumeration ......
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #include<map>
7 #include<set>
8 #include<vector>
9 #include<queue>
10 #include<stack>
11 #include<list>
12 //#include<unordered_map>
13 using namespace std;
14 #define ll long long
15 const int mod=1e9+7;
16 const int inf=1e9+7;
17
18 const int maxn=5e3;
19
20 int sum[maxn+10][maxn+10];
21
22 int main()
23 {
24 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
25
26 int n,r;
27
28 cin>>n>>r;
29 int x,y,w;
30
31 int mn=-1;
32 for(int i=0;i<n;i++)
33 {
34 cin>>x>>y>>w;
35 x++;
36 y++;
37 mn=max(mn,x);
38 mn=max(mn,y);
39 sum[x][y]=w;
40 }
41
42 for(int i=1;i<=mn;i++)
43 {
44 for(int j=1;j<=mn;j++)
45 {
46 sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
47 }
48 }
49
50 int maxx=-1;
51
52 for(int i=r;i<=mn;i++)
53 {
54 for(int j=r;j<=mn;j++)
55 {
56 maxx=max(maxx,sum[i][j]-sum[i-r][j]-sum[i][j-r]+sum[i-r][j-r]);
57 }
58 }
59
60 cout<<maxx<<endl;
61
62 return 0;
63 }