锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕精品久久,久久久久亚洲av无码专区,人妻无码久久一区二区三区免费 http://www.shnenglu.com/397993401/category/14033.html鍦ㄩ剻瑙嗕腑鎴愰暱 璁板綍鎴愰暱鐨勭偣婊?/description>zh-cnSun, 13 Jun 2010 15:27:12 GMTSun, 13 Jun 2010 15:27:12 GMT60姹傛渶澶у瓙搴忓垪 http://www.shnenglu.com/397993401/archive/2010/06/13/117829.html浠樼繑浠樼繑Sun, 13 Jun 2010 15:19:00 GMThttp://www.shnenglu.com/397993401/archive/2010/06/13/117829.htmlhttp://www.shnenglu.com/397993401/comments/117829.htmlhttp://www.shnenglu.com/397993401/archive/2010/06/13/117829.html#Feedback0http://www.shnenglu.com/397993401/comments/commentRss/117829.htmlhttp://www.shnenglu.com/397993401/services/trackbacks/117829.html
#include <iostream>
#include 
<vector>
using namespace std;
int max3( int a, int b, int c )
{
return a > b ? a > c ? a : c : b > c ? b : c;
}

/** 鍒嗘不娉曟眰鏈澶у瓙搴忓垪
 * Recursive maximum contiguous subsequence sum algorithm.
 * Finds maximum sum in subarray spanning a[left..right].
 * Does not attempt to maintain actual best sequence.
 
*/
int maxSumRec( const vector<int> & a, int left, int right )
{
    
if ( left == right ) // Base case
        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 j = center + 1; j <= right; j++ )
    {
        rightBorderSum 
+= a[ j ];
        
if ( rightBorderSum > maxRightBorderSum )
            maxRightBorderSum 
= rightBorderSum;
    }

    
return max3( maxLeftSum, maxRightSum,
                 maxLeftBorderSum 
+ maxRightBorderSum );
}

/**
 * Driver for divide-and-conquer maximum contiguous
 * subsequence sum algorithm.
 
*/
int maxSubSum3( const vector<int> & a )
{
    
return maxSumRec( a, 0, a.size( ) - 1 );
}

/**
 * Linear-time maximum contiguous subsequence sum algorithm.
 
*/
int maxSubSum4( const vector<int> & a )
{
    
int maxSum = 0, thisSum = 0;

    
for ( int j = 0; j < a.size( ); j++ )
    {
        thisSum 
+= a[ j ];

        
if ( thisSum > maxSum )
            maxSum 
= thisSum;
        
else if ( thisSum < 0 )
            thisSum 
= 0;
    }

    
return maxSum;
}
/*
鏈澶ф瀛愬簭鍒?nbsp;鎵鏈夌殑sub 閮戒負姝f暟
*/
int maxSubPositiveSum( const vector<int> & a)
{
    
int maxSum = 0, thisSum = 0,i;
    
bool isPositive[8];
    
for (i = 0 ;i < 8 ; i ++)
        isPositive[i] 
= a[i]>0?true:false;
    
for ( int j = 0; j < a.size( ); j++ )
    {

        
if ( isPositive[j])
        {
            thisSum 
+= a[ j ];
            
if ( thisSum > maxSum )
                maxSum 
= thisSum;
            
else if ( thisSum < 0 )
                thisSum 
= 0;
        }
        
else if (!isPositive[j]  )
            thisSum 
= 0;

    }

    
return maxSum;
}
int main( )
{
    vector
<int> a( 8 );
    a[ 
0 ] = 4;a[ 1 ] = -3;a[ 2 ] = 5;a[ 3 ] = -2;
    a[ 
4 ] = -1;a[ 5 ] = 2;a[ 6 ] = 6;a[ 7 ] = -2;
    
int maxSum,i;

    maxSum 
= maxSubSum3( a );
    cout 
<< "Max sum is " <<  maxSum << endl;
    maxSum 
= maxSubPositiveSum( a );
    cout 
<< "Max sum is " <<  maxSum << endl;

    
return 0;
}




浠樼繑 2010-06-13 23:19 鍙戣〃璇勮
]]>
一级做a爰片久久毛片免费陪| 亚洲嫩草影院久久精品| 伊人久久五月天| 亚洲va中文字幕无码久久不卡| 久久天天躁狠狠躁夜夜网站| 久久综合欧美成人| 久久国产亚洲精品| 久久综合九色综合精品| 色婷婷综合久久久久中文字幕| 久久99亚洲网美利坚合众国| 久久九九久精品国产免费直播| 久久w5ww成w人免费| 日日狠狠久久偷偷色综合96蜜桃| 久久99国产综合精品女同| 亚洲精品tv久久久久| 久久美女人爽女人爽| 久久婷婷国产综合精品| 亚洲va久久久久| 久久久久99精品成人片| 久久久久久久久久久久中文字幕| 日日狠狠久久偷偷色综合免费| 国产V亚洲V天堂无码久久久| 国产69精品久久久久APP下载| 激情五月综合综合久久69| 国产一区二区精品久久| 久久综合狠狠综合久久| 久久天天躁夜夜躁狠狠躁2022| 久久九色综合九色99伊人| 99久久精品免费看国产一区二区三区| 亚洲欧美伊人久久综合一区二区 | 国产∨亚洲V天堂无码久久久| 性高湖久久久久久久久AAAAA| 久久久久亚洲AV成人网| 一本大道久久a久久精品综合| 国内精品久久久久| 久久99精品国产麻豆宅宅 | 国产精品美女久久久免费| 99久久免费国产精精品| 99久久成人国产精品免费| 亚洲国产二区三区久久| 精品人妻伦九区久久AAA片69|