本文主要是介绍Solutions_to_Introduction_to_Algorithm_3nd_Exercise_4,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
4.1-1 What does FIND-MAXIMUM-SUBARRAY return when all elements of A are negative?The biggest negative one.
4.1-2 Write pseudocode for the brute-force method of solving the maximum-subarray problem. Your procedure should run inΘ(n^2);
typedef struct{int max_left;int max_right;int max;
}maxinfo;
maxinfo bf_MaxSubArray(int *a,int n)
{maxinfo max;max.max_left= 0;max.max_right= 0;max.max= MIN_INT;int tmp=0;for(int i=0;i<n;i++){for(int j=i;j<n;j++){tmp += a[j];if(tmp > max.max){max.max = tmp;max.max_left = i;max.max_right = j;}}tmp = 0;}return max;
}
这篇关于Solutions_to_Introduction_to_Algorithm_3nd_Exercise_4的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!