hdu 1559 最大子矩阵

http://acm.hdu.edu.cn/showproblem.php?pid=1559

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <algorithm>

 4 #define maxn 1001

 5 using namespace std;

 6 

 7 int b[maxn][maxn];

 8 int a[maxn][maxn];

 9 int dp[maxn];

10 int n,m,x,y;

11 

12 int main()

13 {

14     int t;

15     scanf("%d",&t);

16     while(t--)

17     {

18         scanf("%d%d%d%d",&n,&m,&x,&y);

19         for(int i=1; i<=n; i++)

20         {

21             b[i][0]=0;

22             for(int j=1; j<=m; j++)

23             {

24                 scanf("%d",&a[i][j]);

25                 b[i][j]=b[i-1][j]+a[i][j];

26             }

27         }

28         int max1=-100;

29         for(int i=x; i<=n; i++)

30         {

31             memset(dp,0,sizeof(dp));

32             for(int j=1; j<=m; j++)

33             {

34                 dp[j]=b[i][j]-b[i-x][j];

35                 dp[j]=dp[j]+dp[j-1];

36                 if(j>=y)

37                     max1=max(max1,dp[j]-dp[j-y]);

38             }

39         }

40         printf("%d\n",max1);

41     }

42     return 0;

43 }
View Code

 

你可能感兴趣的:(HDU)