CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Problem Solving

  1. #1
    Join Date
    Apr 2009
    Posts
    21

    Problem Solving

    So we had a programming tournament at my university on friday and we were given 6 problems. One of them I didn't understand at all and would like to ask you guys to give me some general pointers as to how to solve it.

    Here it is:


    Input: inputB.dat
    Output: standard output device (i.e. console)

    Background
    Problems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing problems is minimizing wire length. The Traveling Salesperson Problem (TSP) -- finding whether all the cities in a salesperson's route can be visited exactly once with a specified limit on travel time -- is one of the canonical examples of an NP-complete problem; solutions appear to require an inordinate amount of time to generate, but are simple to check.

    This problem deals with finding a minimal path through a grid of points while traveling only from left to right.

    The Problem
    Given an m x n matrix of integers, you are to write a program that computes a path of minimal weight. A path starts anywhere in column 1 (the first column) and consists of a sequence of steps terminating in column n (the last column). A step consists of traveling from column i to column i + 1 adjacent, i.e., the matrix "wraps" so that it represents a horizontal cylinder. Legal steps are illustrated below.



    The weight of a path is the sum of the integers in each of the n cells of the matrix that are visited. For example, two slightly different 5 x 6 matrices are shown below (the only difference is the numbers in the bottom row).



    The minimal path is illustrated for each matrix. Note that the path for the matrix on the right takes advantage of the adjacency property of the first and last rows.

    The Input
    The input consists of a matrix specification. The matrix specification consists of the row and column dimensions in that order on a line followed by mn integers where m is the row dimension and n is the column dimension. The integers appear in the input in row major order, i.e., the first n integers constitute the first row of the matrix, the second n integers constitute the second row and so on. The integers on a line will be separated from other integers by one or more spaces. Note: integers are not restricted to being positive. There will be only one matrix specification in an input file. Input is terminated by end-of-file.

    For each specification the number of rows will be between 1 and 10 inclusive; the number of columns will be between 1 and 100 inclusive. No path's weight will exceed integer values representable using 30 bits.

    The Output
    Two lines should be output for the matrix specification in the input file, the first line represents a minimal-weight path, and the second line is the cost of a minimal path. The path consists of a sequence of n integers (separated by one or more spaces) representing the rows that constitute the minimal path. If there is more than one path of minimal weight the path that is lexicographically smallest should be output.

    Sample Input
    5 6
    3 4 1 2 8 6
    6 1 8 2 7 4
    5 9 3 9 9 5
    8 4 1 3 2 6
    3 7 2 8 6 4

    Expected Output
    1 2 3 4 4 5
    16
    I tried using recursion to go through all the possible paths and then find the lightest one until I got stuck on the technical details.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Problem Solving


  3. #3
    Join Date
    Apr 2009
    Posts
    21

    Re: Problem Solving

    lmao

    did you even bother reading my question at all?

    I clearly stated this isn't a homework assignment. Let me repost it for you: This is a problem that was handed out to us during a programming contest that took place a couple days ago.

    I'm not asking for other people's code which you compile, run, and observe but you don't learn ****.

    I'm just looking for insight on how to tackle this problem. I've already written dozens of pages regarding various ways on how to solve this, but as I stated, I'm stuck.

    Just because I don't post more letters doesnt mean that I'm not putting effort into it.

    Thank you very much, have a nice day.

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Problem Solving

    Quote Originally Posted by EsX_Raptor View Post
    I'm not asking for other people's code which you compile, run, and observe but you don't learn ****.

    I'm just looking for insight on how to tackle this problem. I've already written dozens of pages regarding various ways on how to solve this, but as I stated, I'm stuck.
    Then why did you post in the Visual C++ forum? Why not e.g. in the Algorithms forum?

    Anyway, there are numerous approaches you could take to this. You could build a search tree and do a complete enumeration. Or you could have a look at the available shortest path algorithms.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Problem Solving

    Quote Originally Posted by EsX_Raptor View Post
    lmao

    did you even bother reading my question at all?

    I clearly stated this isn't a homework assignment.
    Anything where you state a "problem" with no code, regardless of whether it was given to you in school, or from a programming contest, or for your own study, is a homework problem.

    It's the same thing as if I bought a C++ book for myself, and just posted all the questions from the book here, looking for answers. It still is considered homework. Also, many new posters attempt to disguise homework assignments as pop-quizzes, a "new website looking for source code", and other tricks. The only way to know it isn't a homework assignment is to see what you have done to solve the problem.

    If it isn't related to actual solutions in code, then you should have posted in the Algorithms forum, where the emphasis is not on how to write the final program in C++.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 12th, 2009 at 09:34 AM.

  6. #6
    Join Date
    Jan 2009
    Location
    new york,usa
    Posts
    49

    Re: Problem Solving

    hey. i am a student. you do know that google is your friend? i just searched with the general terms stated above and found plenty of information! i even found some code... but i won't tell you where. the people here are trying to get you to see that you need to work through the algorithm, then apply some effort to coding out your solution. they are more than willing to assist; you just need to put in some work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured