POJ 1050 To the Max
2014-07-17 23:39
288 查看
转换为一维数组求最大连续子段和,然后dp水。
#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int MAXN = 111; int dp[MAXN], mat[MAXN][MAXN]; int subMax(int n, int len){ int ret = mat [0]; dp[0] = mat [0]; for(int i = 1;i < len;i ++){ if(dp[i-1] > 0) dp[i] = mat [i] + dp[i-1]; else dp[i] = mat [i]; ret = max(ret, dp[i]); } return ret; } int main(){ int n; int tmat[MAXN]; //freopen("in.cpp", "r", stdin); while(~scanf("%d", &n)){ for(int i = 0;i < n;i ++){ for(int j = 0;j < n;j ++){ scanf("%d", &mat[i][j]); } } int ans = -0x7fffffff; for(int i = 0;i < n;i ++){ ans = max(subMax(i, n), ans); for(int j = i+1;j < n;j ++){ for(int k = 0;k < n;k ++) mat[i][k] += mat[j][k]; ans = max(subMax(i, n), ans); } } cout << ans << endl; } }
相关文章推荐
- POJ 1050-To the Max (动态规划)
- POJ 1050 To the Max
- zoj 1074 || poj 1050 To the Max(简单DP)
- poj 1050 To the Max
- POJ 1050 To the Max(最大子段)
- poj 1050 To the Max
- poj 1050 To the Max
- POJ 1050 To the Max【最大子矩阵】
- POJ 1050 To the Max (动态规划——求最大子矩阵和)
- POJ-1050-To the Max 解题报告
- POJ 1050 To the Max
- POJ 1050 To the Max
- POJ 1050 To the Max
- poj 1050 To the Max
- 【原】 POJ 1050 To the Max 求二维矩阵的最大子矩阵 解题报告
- DP::Poj1050 To the max
- POJ 1050 To the Max
- poj1050 To the Max
- POJ_1050_To the Max
- POJ 1050 To the max 最大子矩阵