HDU 1081 To The Max 最大子矩阵和 .
2016-10-02 13:34
423 查看
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1081
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=100+5;
const int INF=0x3f3f3f3f;
int Grid[maxn][maxn],d[maxn];
int MaxSum(int n)
{
int ans=-INF,temp=0;
for(int i=0;i<n;i++){
if(temp>0) temp+=d[i];
else temp=d[i];
ans=max(ans,temp);
}
return ans;
}
int solve(int n)
{
int ans=-INF;
for(int i=0;i<n;i++)
{
memset(d,0,sizeof(d));
for(int j=i;j<n;j++)
{
for(int k=0;k<n;k++)
d[k]+=Grid[j][k];
ans=max(ans,MaxSum(n));
}
}
return ans;
}
int main(int argc, char const *argv[])
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&Grid[i][j]);
cout<<solve(n)<<endl;;
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=100+5;
const int INF=0x3f3f3f3f;
int Grid[maxn][maxn],d[maxn];
int MaxSum(int n)
{
int ans=-INF,temp=0;
for(int i=0;i<n;i++){
if(temp>0) temp+=d[i];
else temp=d[i];
ans=max(ans,temp);
}
return ans;
}
int solve(int n)
{
int ans=-INF;
for(int i=0;i<n;i++)
{
memset(d,0,sizeof(d));
for(int j=i;j<n;j++)
{
for(int k=0;k<n;k++)
d[k]+=Grid[j][k];
ans=max(ans,MaxSum(n));
}
}
return ans;
}
int main(int argc, char const *argv[])
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&Grid[i][j]);
cout<<solve(n)<<endl;;
}
return 0;
}
相关文章推荐
- hdu1081 To The Max--DP(最大子矩阵和)
- hdu 1081 To The Max 【最大子矩阵和】
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)
- HDU 1081 To The Max(最大子矩阵和)
- HDU 1081 To The Max(最大子矩阵和)
- hdu 1081 To The Max(最大子矩阵)
- HDU 1081 To The Max(最大子矩阵和)
- HDU 1081 To The Max(dp最大子矩阵和)
- HDU - 1081 To The Max ( 最大子矩阵)
- hdu-1081 To The Max (最大子矩阵和)
- hdu 1081 To The Max(最大子矩阵)
- HDU 1081 To The Max(dp最大子矩阵和)
- hdu 1081 To The Max ****poj 1050(最大子矩阵和)DP
- hdu 1081 To The Max(最大子矩阵和,dp)
- HDU 1081 To The Max--DP--(最大子矩阵)
- hdu 1081 To The Max(最大子矩阵和)
- dp - 最大子矩阵和 - HDU 1081 To The Max
- hdu 1081 To The Max 最大子矩阵和(dp)
- hdu 1081、poj1050 To The Max 最大子矩阵和
- hdu 1081 To The Max ( 最大子矩阵 )