POJ 1050 To the Max
来源:互联网 发布:php beast master 编辑:程序博客网 时间:2024/06/18 18:49
转换为一维数组求最大连续子段和,然后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[n][0]; dp[0] = mat[n][0]; for(int i = 1;i < len;i ++){ if(dp[i-1] > 0) dp[i] = mat[n][i] + dp[i-1]; else dp[i] = mat[n][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; }}
0 0
- 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
- 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
- ALM版本与系统需求
- Use angular-css-injector to inject CSS into Angular templates
- LongClickProject
- Linux守护进程的编程实现
- GUava集合[Collections]2.1-不可变集合
- POJ 1050 To the Max
- js中Date
- vs2010 快捷键大全
- NestedLayout
- 高精度模板
- RatingBarProject
- 步进电机控制下位机程序
- Hibernate中的条件查询完成类
- [Google Guava] 2.2-新集合类型