码迷,mamicode.com
首页 > 其他好文 > 详细

集合求子集最大值

时间:2015-08-27 12:39:46      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

$arr = array(10,20,30,-100,7,8,9);
 
function getResult($arr) {
    $n = count($arr);
    $result = $arr[0];
    $t = $arr[0];
   
    for ($i = 1; $i < $n; $i++) {
        echo $t . ‘--------‘;
        if ($t < 0) {
            $t = 0;
        }
       
        $t += $arr[$i];
        echo $t . ‘--------‘;
       
        if($t > $result)
        {
            $result = $t;
        }
        echo $result . ‘<br/>‘;
    }
    return $result;
   
}
 
print_r(getResult($arr));

集合求子集最大值

标签:

原文地址:http://www.cnblogs.com/cdy07341/p/4762857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!