POJ 1050 二维子数组最大值
2012-12-01 13:59
288 查看
//11068092 c00h00g 1050 Accepted 4736K 47MS C++ 1140B 2012-12-01 13:59:06 //参考的编程之美上给出解法 //收获:对于一维的数组a[i],要求其最大连续子串和,我们只需要设计一个变量tmp=0(初值) //for(int i=1;i<=n;i++){ // tmp=max(tmp+a[i],a[i]) // }而不需要设计dp[i] #include<stdio.h> #include<stdlib.h> #include<limits.h> #include<string.h> #include<algorithm> using namespace std; int N; int mat[105][105]; //用于记录某列的第i行到第j行的和 int sum_col[105][105][105]; int main(){ while(scanf("%d",&N)!=EOF){ for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){ scanf("%d",&mat[i][j]); } //对第i列来说,求第j行到第k行的和 memset(sum_col,0,sizeof(sum_col)); //预处理 for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ for(int k=j;k<=N;k++){ for(int m=j;m<=k;m++) sum_col[i][j][k]+=mat[m][i]; } } } // int res=-INT_MAX; for(int i=1;i<=N;i++){ for(int j=i;j<=N;j++){ //对每一列来说 int tmp=0; for(int k=1;k<=N;k++){ tmp=max(tmp+sum_col[k][i][j],sum_col[k][i][j]); res=max(res,tmp); } } } printf("%d\n",res); } return 0; }
相关文章推荐
- POJ 1050 To the Max【求最大的子矩阵和同上一篇数组中最大连续和】
- 连续子数组的最大和问题(一维和二维)To the Max (POJ 1050)
- poj1050最大字段和及其衍生
- POJ 1050-To the Max(最大子矩阵和)
- POJ 1050 To the Max(DP_最大字段和)
- 51Nod-1050-循环数组最大子段和
- poj 1050 To the Max(动态规划处理二维最大子段和)
- 1050 循环数组最大子段和
- 51nod 1050 循环数组最大子段和
- Poj1050_To the Max(二维数组最大字段和)
- POJ 1050 To the Max (最大子矩阵和)
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)
- POJ 1050 To the Max【最大子矩阵】
- POJ 1050,HDU 1003 最大连续子序列和
- POJ 1050 to the max最大子矩阵
- 51nod 1050 循环数组最大子段和
- POJ 1050 To the Max(dp 最大子矩阵和/最大子段和问题)
- poj 1050 To the Max 最大子矩阵和
- POJ 1050 / HDU 1081 To the Max(最大子矩阵和)
- poj 1050 To the Max(最大子矩阵和)