CONSOLE APPLICATION 3
analyse problem
Proposal max-subarray-problem [O(n^2)]
brute-force algorithm:
#include "stdafx.h"
#include<iostream>
#include<stdio.h>
using namespace std;
//brute-force algorithm
int main()
{
int n = 0, sum = 0;
int q = 0, w = 0, e = 0, r = 0;
cout << "this this brute force\t\n";
cout << "input the array size\n";
cin >> n;
int*maxarray = new int[n];
int i = 0;
cout << "please input array\n";
for (; i < n; i++)
{
cin >> maxarray[i];
}
int tmp = 0,maxtmp=0;
for (i = 0; i < n; i++)
{
for (w = i + 1; w < n; w++)
{
for (e = i; e < w; e++)
{
sum = 0;
sum += maxarray[e];
}
tmp = sum;
if (tmp > maxtmp)
maxtmp = tmp;
}
}
cout << "the max subarray" << maxtmp << endl;
return 0;
}
But now,I can’t analyse this algorithm.
what else I also can’t figure out the divide-conquer way.