小编use*_*741的帖子

查找数组中元素的最大总和(带扭曲)

给定具有+ ve和-ve整数的数组,找到最大总和,以便不允许跳过2个连续元素(即,您必须选择其中至少一个向前移动).

例如: -

10,20,30,-10,-50,40,-50,-1,-3

输出:10 + 20 + 30-10 + 40-1 = 89

algorithm logic kadanes-algorithm

5
推荐指数
2
解决办法
1万
查看次数

在c ++中返回对局部变量的引用

下面的代码是错误的?我正在返回对本地变量的引用...它应该是核心转储,但它正在执行正常.以下代码在我的系统上工作正常,因为我是LUCKY?

#include<iostream>
using namespace std;

class a{
    public:
    int i;
    int arr[20];
    a()
    {
        cout<<"\ninside constructor";
        i=10;
    }
    public:
    static a& ret()
    {
        a chk;
        return chk;
    }
    void say()
    {
        i=10;
        arr[0]=1;
        cout<<"\nHello World\n";
    }

};


int main()
{
(a::ret()).say();
return 1;
}
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
2
解决办法
102
查看次数

标签 统计

algorithm ×1

c++ ×1

kadanes-algorithm ×1

logic ×1