您的位置:首页 > 其它

【动态规划】HDU1559最大子矩阵

2017-09-06 16:17 190 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559

/*
指定大小的最大子矩阵和
遍历每一个指定大小的矩阵
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1050;
const int M=1050;
int dp
[M]={0}; // 从1,1到i,j的矩阵和
int main()
{
int t,n,m,x,y;
cin>>t;
while(t--){
cin>>n>>m>>x>>y;
memset(dp,0,sizeof(dp));
int Max=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>dp[i][j];
dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; // 画图分析
if(i>=x&&j>=y)
Max=max(Max,dp[i][j]-dp[i-x][j]-dp[i][j-y]+dp[i-x][j-y]); // 每一个点都有对应的大小为x,y的矩阵
}
}
cout<<Max<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  动态规划