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)