hdu 1081 To The Max
2014-04-04 20:47
330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1081
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300
using namespace std;
const int inf=0x7fffffff;
int dp[maxn][maxn];
int a[maxn][maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1; i<=n; i++)
{
dp[i][0]=0;
for(int j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
dp[i][j]=dp[i][j-1]+a[i][j];
}
}
int max1=-inf;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
int c=0;
for(int k=1; k<=n; k++)
{
c+=(dp[k][i]-dp[k][j-1]);
if(max1<c)
max1=c;
if(c<0)
c=0;
}
}
}
printf("%d\n",max1);
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300
using namespace std;
const int inf=0x7fffffff;
int dp[maxn][maxn];
int a[maxn][maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1; i<=n; i++)
{
dp[i][0]=0;
for(int j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
dp[i][j]=dp[i][j-1]+a[i][j];
}
}
int max1=-inf;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
int c=0;
for(int k=1; k<=n; k++)
{
c+=(dp[k][i]-dp[k][j-1]);
if(max1<c)
max1=c;
if(c<0)
c=0;
}
}
}
printf("%d\n",max1);
}
return 0;
}
相关文章推荐
- HDU1081 To The Max
- HDU 1081 To The Max(最大子矩阵)
- hdu 1081 To The Max
- HDU 1081 To The Max
- HDU 1081 To The Max(动态规划)
- To The Max_hdu_1081(经典DP).java
- 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(DP)
- hdu 1081 to the max
- hdu 1081 To The Max
- 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(最小子阵和)
- HDU1081 To The Max