POJ 1050-To the Max
来源:互联网 发布:java ioc原理 编辑:程序博客网 时间:2024/06/03 22:03
太久没做题了 , 没什么思路的说 。。
看了别人的解体报告后,感觉好神奇啊。只要把后面的各个行依次加到前一行,再求一维数组的最长子序列和。。有点像每次假设一个小矩阵,在这矩阵中寻找最大矩阵和 而这些小矩阵就是 人为通过扩大矩阵宽度以及起始行来实现的
学习了~~~~~
#include<iostream>#include<stdio.h>using namespace std;#define N 105int a[N][N];int maxSub(int a[],int n){int msum=-128,sum=0,l,r;l=r=0;while(r<n){if(sum+a[r]<a[r])sum=a[r];elsesum+=a[r];r++;if(msum<sum)msum=sum;}return msum;}int main(){int i,n,j,k,max=-128,s;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);for(i=0;i<n;i++){ s=maxSub(a[i],n);if(s>max)max=s;for(j=i+1;j<n;j++){for(k=0;k<n;k++)a[i][k]+=a[j][k];s=maxSub(a[i],n);if(s>max)max=s;}}printf("%d\n",max);return 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
- javascript中的表格操作
- sqlite例子学习
- java中的for循环
- Oracle异常处理
- Android USB 主机模式
- POJ 1050-To the Max
- FFmpeg浅尝辄止(二)——YUV视频序列编码为视频
- Android中Activity启动模式详解
- 【让你操作Windows于弹指之间§小米跟你说】
- css 背景
- Android(Java):在textview中显示富文本
- Linux:Clock skew detected. Your build may be incomplete.解决办法
- Java以utf8保存为文本文件
- c++构造函数和析构函数调用规则