poj 1050
来源:互联网 发布:java定义长整型 编辑:程序博客网 时间:2024/04/30 05:46
传送门http://poj.org/problem?id=1050
将2维的dp压成1维的
将数组每列的和放在一个数组temp中
用temp求最大连续子序列
#include<iostream>#include<cstdio>#include<cstring>#define maxn 105using namespace std;int a[maxn][maxn];int temp[maxn];int dp[maxn];int main(){ int max=-0x3fffffff; int n; cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); dp[1]=1; for(int i=1;i<=n;i++)//从第几行 { memset(temp,0,sizeof(temp));//注意清零 for(int j=i;j<=n;j++)//到第几行 { for(int k=1;k<=n;k++)//第几列在temp里的第几个数字 temp[k]+=a[j][k]; int maxx=-0x3fffffff; int x=temp[1]; for(int i=2;i<=n;i++) { if(x<0) x=temp[i];//sum=0的不是最大子串 //最大子串第一个跟最后一个不是负的 else x+=temp[i]; if(maxx<x) maxx=x;//更新最大值 } if(maxx>max) max=maxx; } } cout<<max<<endl;}
- POJ 1050
- poj 1050
- POJ 1050
- POJ 1050
- poj 1050
- poj 1050
- POJ 1050
- poj 1050
- poj--1050
- poj 1050
- POJ 1050
- POJ 1050
- Poj 1050
- POJ 1050
- poj-1050
- poj 1050
- poj 1050
- POJ 1050
- Android应用程序快速启动的秘诀
- mongodb 记录
- MYSQL常用技术
- uCOS运行时堆栈管理
- 代码的抽象三大原则
- poj 1050
- Linux下 mutt和msmtp发送邮件
- GoldenGate SQL error 1403 OGG-01296 Error mapping
- Java任意两个大整数相乘
- 用拦截器,注解实现权限
- <iOS>关于自定义description的一点用法
- 第三篇:cydia卸载和更新软件
- ubuntu驱动开发环境配置
- 焦点图触屏划动处理