2018.3.17
分治算法求最大子列和
基本思想为二分分治并递归求解左子列最大和、右子列最大和、跨中线子列最大和,比较求出最大和。
“最大子列和”则被定义为所有连续子列元素的和中最大者。
例如给定序列{ -2, 11, -4, 13, -5, -2 },其连续子列{ 11, -4, 13 }有最大的和20。
Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.
基本思想为二分分治并递归求解左子列最大和、右子列最大和、跨中线子列最大和,比较求出最大和。
// MaxSubsequence2.cpp : 定义控制台应用程序的入口点。
// 分治算法求最大子列和
// 基本思想为二分分治并递归求解左子列最大和、右子列最大和、跨中线子列最大和,比较求出最大和。
//“最大子列和”则被定义为所有连续子列元素的和中最大者。
//例如给定序列{ -2, 11, -4, 13, -5, -2 },其连续子列{ 11, -4, 13 }有最大的和20。
//Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#define MAX 100000
int MaxSubseq(int n, int data[]);
void Read(int n, int data[]);
int Max3(int A, int B, int C);
int DivideAndConquer(int data[], int