HDU ACM 1081 最大子矩阵问题
2014-11-13 16:42
267 查看
子矩阵肯定是1行,2行,……,n行的。
求出行数为1的最大子矩阵的值,行数为2的最大子矩阵的值,……,行数为n时的最大子矩阵的值。
保存在数组sub_max中, 然后sub_max中的最大值就是最大子序列。
求出行数为1的最大子矩阵的值,行数为2的最大子矩阵的值,……,行数为n时的最大子矩阵的值。
保存在数组sub_max中, 然后sub_max中的最大值就是最大子序列。
#include<iostream> using namespace std; const int M = 105; int table[M][M] = {0}; int arry[M]= {0}; int sub_max[M]; inline int max_(const int &a,const int &b) { return a>b?a:b; } int max_subsquence(const int &n_) { int res,tmp_; res = tmp_ = arry[0]; for(int z = 1 ; z < n_ ; z++) { tmp_ = max_(arry[z],tmp_+arry[z]); if(tmp_>res)res = tmp_; } return res; } int main() { int n,tmp,i,j,row,result,tmp_submax; while(cin >> n) { for(i = 0 ; i < n ; i ++) { sub_max[i] = -500; for(j = 0 ; j < n ; j++)cin>>table[i][j]; } for(row = 1 ; row <= n ; row++) for(i = row-1 ; i < n ; i++) { // cout<<endl << i <<":"; for(j = 0 ; j < n ; j++) { tmp = i; for(int x = 0; x < row ; x++) { arry[j] += table[tmp--][j]; } // cout << arry[j] << " "; } tmp_submax = max_subsquence(n); if(tmp_submax > sub_max[row-1])sub_max[row-1] = tmp_submax; for(int y = 0 ; y <n ; y++)arry[y] = 0; } result = sub_max[0]; for(i = 1; i <n ; i++)result = max_(result,sub_max[i]); cout <<result<<endl; } return 0; }
相关文章推荐
- HDU 1081(最大子矩阵问题)
- 最大子矩阵问题hdu 1081
- 最大子矩阵问题
- pku1050 最大子矩阵问题
- HDU 1081 To The Max(最大子矩阵和)
- USACO 3.3 Home on the Range(最大子矩阵问题)
- HDU 1081 最大子矩阵
- 最大子矩阵问题
- HDU 1081 & POJ 1050 To The Max (最大子矩阵和)
- hdu 1081、poj1050 To The Max 最大子矩阵和
- 【算法设计】最大子矩阵问题
- dp解决最大子矩阵问题
- 最大子矩阵问题
- 最大子矩阵问题
- pku poj 1050 最大子矩阵问题
- 最大子矩阵问题
- 动态规划解决最大子矩阵问题
- 最大子矩阵问题
- HDU 1081 To The Max (DP) 扩展最大子列和,求最大子矩阵和
- 最大子矩阵问题 PKU 1050