【算法设计与分析】To the max
来源:互联网 发布:双系统软件不能用 编辑:程序博客网 时间:2024/06/03 05:07
【题目】
【输入与输出】
【源代码】
//思路简述:这是一个可以化为选出最大子序列的问题,首先对一行进行选取,选出以当前数结束的序列的和的最大值//然后将每一行的每一列数逐次加起来,形成一个新的序列,再一次进行选择,max不断被取缔#include<stdio.h>#include<string.h>#define MAXN 105#define INF -1000int srow[MAXN];int num[MAXN][MAXN];int main(int argc,char *argv[]){int n;int i;int j;int k; int rmax=INF;int nsum; scanf("%d",&n);//输入矩阵大小memset(num,0,sizeof(num));for(i=1;i<=n;i++){for(j=1;j<=n;j++)scanf("%d",&num[i][j]);//输入矩阵各点的值}for(i=1;i<=n;i++){memset(srow,0,sizeof(srow));for(j=i;j<=n;j++){nsum=0;//每一次清零for(k=1;k<=n;k++){srow[k]+=num[j][k];//将两行的同列相加if(nsum>0) //将同列相加的数看作是一维数组求最大子序列和nsum+=srow[k];elsensum=srow[k];if(nsum>rmax)rmax=nsum;//更换最大值}}}printf("%d\n",rmax);return 0;}
【简要分析】
0 0
- 【算法设计与分析】To the max
- 【算法分析与设计】【第七周】200 & 695. Number(Max Area) of Islands
- zoj1074 To the Max
- 1074 To the Max
- 1050 To the Max
- POJ1050 To the Max
- POJ1050 To the Max
- POJ to The Max
- 1081 To The Max
- To the Max
- To the max(hdu1081)
- POJ To the Max
- 1050--To the Max
- POJ1050 To the Max
- poj1050 to the max
- To The Max
- HDU1081--To The Max
- poj1050 To the Max
- LeetCode 372 Super Pow
- 16.1 Windows上安装PySide
- SQL看语句执行时间
- jquery和ajax 的区别
- location.search
- 【算法设计与分析】To the max
- 九、STL算法-排序算法(sort)
- C语言基础
- C语言---函数返回值探究
- android 视图自动注入的第三方库-ButterKnife插件用法介绍
- hud 1260 Tickets (简单dp)
- 关于app的几个核心功能的设计想法
- BZOJ 1115: [POI2009]石子游戏Kam
- oracle 12c:新特性-截断表CASCADE