c ++ – Sub-matrix maximum sum and these index-Divide and Conquer

My code above on the search for the maximum sum of sub-matrix and search for the beginning index, the end index of this sub-matrix.

int Max(int a,int b){return (a>b)?a:b;}
int Max(int a,int b,int c){return Max(Max(a,b),c);}
int MaxAcrossSubArray(int arr(),int l,int m,int r,int &Start,int &End) 
{
    Start=m;//initialize start index
    int sum=arr(m);
    int sum_l=arr(m);
    for(int i=m-1;i>=l;--i)//include mid(---------|)
    {
        sum+=arr(i);
        if(sum>sum_l)
        {
            Start=i;
            sum_l=sum;
        }

    }
    End=m+1;//initialize end index
    sum=arr(m+1);
    int sum_r=arr(m+1);
    for(int i=m+2;i<=r;++i)//include mid(|-----------------)
    {
        sum+=arr(i);
        if(sum>sum_r){
            End=i;
            sum_r=sum;
        }
    }
    return sum_l+sum_r;//(-----------|---------------------)

}
int MaxSubArray(int arr(),int l,int r,int &Start,int &End)
{
    if(l==r)
    {
        Start=l;
        End=r;
        return arr(l);
    }

    else
    {
       int mid=(l+r)/2;
        int sA=-1,eA=-1,sB=-1,eB=-1,sC=-1,eC=-1;
        int a=MaxSubArray(arr,l,mid,sA,eA);
        int b=MaxSubArray(arr,mid+1,r,sB,eB);
        int c=MaxAcrossSubArray(arr,l,mid,r,sC,eC);
        int Maximum=Max(a,b,c);

        if(Maximum==a)
        {
            Start=sA;
            End=eA;
            return a;
        }

        else if(Maximum==b)
            {
                Start=sB;
                End=eB;
                return b;
            }
        else
            {
                Start=sC;
                End=eC;
                return c;
            }
    }
    }

}
int main()
{
    int arr(9)={-2, 1, -3, 4, -1, 2, 1, -5, 4};
    int Start=-1;
    int End=-1;


    cout<

My algorithm works well in all cases, but I still need you to help me improve my algorithm to make it better. Is there a way to improve it?

Integer function indices in a sum

I have some problems with the graphs A and p, especially for the function F (s, l, p), I do not know how to handle the indices of the integer functions of the sum. How can I enter such a sum in Mathematica ?. Thanks in advance

Sum of two Hermitian matrices

How can I prove that any square matrix $ M_n ( mathbb {C}) $ can be written in the form of $ A = B + iC $ with B and C being Hermitian matrices?

A book to explain the direct sum and direct product by diagrams.

A book to explain the direct sum and the direct product by diagrams (commutative diagrams). And also a book to explain the pushout and the pullout by diagrams.

Thank you!

python – Python3 – Sum of the problems of precision between negative and positive number

I am a python class and a user asked a question that I found interesting.

It turns out that if we do the following in python

def suma(num1, num2):
    return num1 + num2

print(suma(4.2, 6))

The result is 1.79999999999999999998

it's not 1.8 as it should be, so it arrives with all decimals of 4 except for 4.5

I find it very strange because with 4.5 the result is correct 5.5

A logical explanation about this?

sum of specific lines

How can you summarize specific lines? When I add up specific lines such as A10: B20: C30, I get the whole column that doubles the numbers. He picks up the specific totals plus the individual columns

time complexity – multiset variant of the sum problem of known algorithms

I was working on the temporal analysis of a solver that I designed for the problem of the sum of subsets (multiset variant) and that the temporal complexity depended on the number of elements repeated. in the entrance.

The temporal complexity is $ O (2 ^ {n / 2} cdot 0.75 ^ { frac {d / 2} {n}} $ or $ d = $ Number of duplicates in the instance of entry (assuming both $ n $ and $ d $ are even)

For example, when $ d = n / 2 $ then:

$ O (2 ^ {n / 2} cdot 0.75 ^ { frac {n / 4} {n}}) approx Y (1.4142 cdot 0.93) approx O (1.316 ^ n) $

In addition to asking for comments, I am also looking for other known algorithms with similar behavior to compare approaches (have searched for them but found nothing so far …)

maximum sum of k contiguous sub-matrices

The question that arises is this: given an array of size n: array () and a number "m", our goal now is to find AT MOST m contiguous sub-matrices so that the sum of all these under -matrices be the biggest. It is also required that none of these subnets can overlap.

Example: for an array (1, 2, 3, -2, 3, -10, 3), if m = 2, the sub-tables we take are (1, 2, 3, -2, 3) and ( 3) and their total sum is 10.
If m = 4, given the same array, then the subnets we end up taking are (1, 2, 3), (3) and (3) and their total sum is 12 (we did not no need for the 4th sub-array here).

Someone has a solution?

Thank you!

Sum equal to lcm

Are there n distinct natural numbers whose sum is equal to their lcm? (N> 2)
Which lcm is the smallest common multiple
I've thought a lot, but the only thing I've found is that n is equal to 3, 4 and 5.
I've tried separate fractions whose sum is equal to 1 but they have not given me n distinct fractions …
Well help me please to handle this problem.
(This was in a book of the Iranian NT Olympiad)

Sum of n sums, permutations of indices, how to write them in Mathematica?

I was wondering how to write a function $ F (r, q, n, f) $ in Mathematica, defined in this way:

$$ F (r, q, n, f): = sum_ {i_0 = 1} ^ qf (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {q + 1} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {q + 2} f (i_2) Bigl ( ldots ( sum_ {i_n = i_ {n-1} +1} ^ {q + n} f (i_n) ) ldots Bigl) biggl) Biggl) $$
es.
$$ sum_ {i_0 = 1} ^ 2 f (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {3} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {4 } f (i_2) biggl) Biggl) = f (1) f (2) f (3) + f (1) f (2) f (4) + f (1) f (3) f (4) + + f (2) f (3) f (4) $$

is there already an operator usable in this way?

trying to write this function on mathematica, I realized that the "recursion" was variable and I did not know how to program in this case.

Thank you

$ $

$ $

another example

$$ sum_ {i_0 = 1} ^ 1 f (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {2} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {3 } f (i_2) ( sum_ {i_3 = i_2 + 1} ^ {4} f (i_2)) biggl) Biggl) = f (1) f (2) f (3) f (4) $$