To find the maximum Subarray two (pair development)

Source: Internet
Author: User

Pair Partner :

Guillechang

Blog Name: We're all little monsters.

Links: http://www.cnblogs.com/qwer113/

Design ideas:

1: Random input of an array

2: Use the direct exhaustive method to find the maximum of the array and (the array as a ring)

3: Defines a struct, when the maximum array is found, the position of the beginning and end of the array is recorded

4: Output

Program Source code:

Dynamic programming//2016/3/26#include "iostream" using namespace std, #define N 100typedef struct data//define struct body {int Kaishi;    int Jieshu; int value;}    Data;int Main () {//any input an array int num = 0;    int a[n];    cout << "arbitrary input an array:";        while (true) {cin >> a[num];        num++;        if (getchar () = = ' \ n ') {break;    }} data Start;    Data all;    Initialize Start.kaishi = All.kaishi = 0;    Start.jieshu = All.jieshu = 0;    Start.value = All.value = A[0];        Direct exhaustive method to find out the maximum value of the ring array//record the starting position and end position of the array for (int i = 0; i < num; i++) {start.value = 0;        Start.kaishi = i;            for (int j = i; j < num; J + +) {Start.value + = A[j];            Start.jieshu = j;        if (start.value>all.value) all = Start;            } for (int j = 0; J < i; J + +) {Start.value + = A[j];            Start.jieshu = j; if (start.value>all.value) all = StArt }}//output cout << start position: <<All.kaishi+1<<endl<< End Position: <<all.jieshu+1<<endl<& lt; "    Last and for: "<< all.value<<endl; return 0;}

Run:

Project Plan Summary:

Time log:

Bug log:

To find the maximum Subarray two (pair development)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.