Thread: maximum sum of subarray

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    23

    maximum sum of subarray

    Given a M × M array of positive and negative integers, find the sub-rectangle with the largest sum. A sub-rectangle is any contiguous sub-array of size 1 × 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. The input to the program is the value of M followed by the array itself.
    Input:
    First line contains M ( 1 <= M<= 100 )
    Next M lines contains M elements each, describing the matrix A ( -100 <= A[i][j] <= 100 )
    Output:
    The Maximum Sum (Followed by a '\n' which is just for a newline, no need to display)
    Sample Cases:
    Input:
    4
    0 -2 -7 0
    9 2 -6 2
    -4 1 -4 1
    -1 8 0 -2
    Output:
    15
    how to solve this one!!!

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    With fgets i said on the other post you read every line in an array.Then from the array retrieve the numbers.They are seperated by a white space.In order to read M use scanf.However,everybody tells you to first write your own try(code or/and idea) but you do not follow their advice

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    23
    Quote Originally Posted by std10093 View Post
    With fgets i said on the other post you read every line in an array.Then from the array retrieve the numbers.They are seperated by a white space.In order to read M use scanf.However,everybody tells you to first write your own try(code or/and idea) but you do not follow their advice
    i have my own idea ...but trying to get some more ways to solve the problem so that i can choose a optimal one...thats it....and for the other problems first i gave the algorithm...
    anyways thanku for the suggestion :-)

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    std10093 is right ... all your initial posts so far ask "how to solve it?":

    pipelining

    hey i ahve assigned to implement a shell...implementing it in C language.but now got stuck on pipelinig...kindly help me guys...
    if possible send the code so that i can get some idea for example that run ls|wc

    how to solve this problem

    You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
    Each digit is allowed to occur in the number the same number of times it occurs in the set.

    permutation of strings

    if one string is permutation of other ....
    how to solve it???

    maximum sum of subarray

    ...
    how to solve this one!!!
    If you really have your own idea for this one, post it and let others comment on how you can improve it. Don't expect everyone to just put up their own ideas (read: do your work for you) so you can "choose an optimal one."

    Show us what you have so far and we can proceed from there.

  5. #5
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Try implementing this and come back to us if you get stuck.

    UVa 108 - Algorithmist
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Good catch, Matticus.
    Students are expected to solve the problem first, then code it.
    So it's less of a programming problem and more of a devise an algorithm problem.
    The good helpers on this forum are duped into solving a C issue even though we are not even coding yet.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extract 2D subarray using MPI_Type_vector()
    By DerekC in forum C Programming
    Replies: 2
    Last Post: 03-06-2010, 06:24 PM
  2. Max Subarray challenge
    By abriggs2 in forum C++ Programming
    Replies: 3
    Last Post: 08-28-2008, 05:29 PM
  3. Replies: 4
    Last Post: 01-05-2008, 11:30 PM
  4. Cin Maximum characters.
    By bladerunner627 in forum C++ Programming
    Replies: 9
    Last Post: 02-01-2005, 12:42 PM
  5. maximum
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-12-2002, 06:03 PM