标签:ane style auth ted bsp enter mis key bottom
Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5199 Accepted Submission(s): 2747
1 //2017-09-24 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 7 using namespace std; 8 9 const int N = 1010; 10 11 int a[N][N], dp[N][N], n, m, x, y; 12 13 int main() 14 { 15 int T; 16 scanf("%d", &T); 17 while(T--){ 18 scanf("%d%d%d%d", &n, &m, &x, &y); 19 for(int i = 0; i < n; i++) 20 for(int j = 0; j < m; j++){ 21 scanf("%d", &a[i][j]); 22 dp[i][j] = a[i][j]; 23 } 24 for(int i = 1; i < n; i++) 25 for(int j = 0; j < m; j++) 26 dp[i][j] += dp[i-1][j]; 27 for(int j = 1; j < m; j++) 28 for(int i = 0; i < n; i++) 29 dp[i][j] += dp[i][j-1]; 30 int ans = 0; 31 for(int i = x-1; i < n; i++) 32 for(int j = y-1; j < m; j++){ 33 int a = i-x+1; 34 int b = j-y+1; 35 int tmp = dp[i][j]; 36 if(a-1>=0)tmp -= dp[a-1][j]; 37 if(b-1>=0)tmp -= dp[i][b-1]; 38 if(a-1>=0 && b-1>=0)tmp += dp[a-1][b-1]; 39 ans = max(ans, tmp); 40 } 41 printf("%d\n", ans); 42 } 43 44 return 0; 45 }
标签:ane style auth ted bsp enter mis key bottom
原文地址:http://www.cnblogs.com/Penn000/p/7586591.html