根據以下最大子序列求和的程式檔案,畫出N-S圖和程式流程圖。
Private static int maxSumRec(int[] a,int left,int right){
if(left==right)
if(a[left]>0){
return a[left];
}else{
return 0;
}
int center=(left+right)/2;
int maxLeftSum=maxSumRec(a, left, center);
int maxRightSum=maxSumRec(a, center+1, right);
int maxLeftBorderSum=0,leftBorderSum=0;
for(int i=center;i>=left;i--)
{
leftBorderSum+=a[i];
if(leftBorderSum>maxLeftBorderSum){
maxLeftBorderSum=leftBorderSum;
}
}
int maxRightBorderSum=0,rightBorderSum=0;
for(int i=center+1;i<=right;i++){
rightBorderSum+=a[i];
if(rightBorderSum>maxRightBorderSum){
maxRightBorderSum=rightBorderSum;
}
}
return max(maxLeftSum,maxRightSum, maxLeftBorderSum+maxRightBorderSum);
}
要求:實驗結果中列出所需的程式流程圖和N-S圖。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/220933.html
標籤:Eclipse
上一篇:java字串連接
下一篇:保留變數的正則運算式怎么替換?
