POJ 1050.To the Max
来源:互联网 发布:美工这个工作发展前景 编辑:程序博客网 时间:2024/06/05 09:43
题目大意
给定一个N*N的矩阵,求一个子矩阵,使子矩阵中各个元素的和最大。
N≤100
题解
由于N≤100,所以我们直接枚举子矩阵的两个行的边界,然后再枚举列数即可。
如果子矩阵中各个元素的和小于0,则不管。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#define N 110#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;int n,i,j,k,ans,sum,a[N][N],c[N][N];int main(){ scanf("%d",&n); fo(i,1,n) fo(j,1,n) { scanf("%d",&a[i][j]); c[i][j]=c[i][j-1]+a[i][j]; } fo(i,1,n) fo(j,i,n) { sum=0; fo(k,1,n) { sum+=c[k][j]-c[k][i-1]; if (sum<0) sum=0; ans=max(ans,sum); } } printf("%d",ans);}
3 0
- POJ 1050. To the Max
- POJ 1050.To the Max
- POJ to The Max
- POJ To the Max
- POJ 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
- mybatis查询字段为空返回另一个字段的值
- [leetcode] 103. Binary Tree Zigzag Level Order Traversal
- Map与JavaBean互转原理(内省机制)
- 求n^k的前几位数和后几位数
- mipi 调试经验
- POJ 1050.To the Max
- 时区设置
- Visual Studio 2015简体中文企业版/专业版下载+有效激活密钥
- rabbitmq 路由 java实现
- SDUT OJ 3378 数据结构实验之查找六:顺序查找
- gettext简介
- ApaChe CorDova 的安装步骤(MAC)和创建IOS版的CorDova
- play framework 2.5.6 win下的安装
- 如何调出阿宝色?