Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Knapsack problem , check if matrix can fill list of smaller matrix list.

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Knapsack problem , check if matrix can fill list of smaller matrix list.

    Hi, i have a list of arrays ( of sizes , for example : 3X1 , 4X2 and so on..) i want to check if i can put all of them in one matrix.
    i need to do it in a recursive way.
    the function i need to write is get the size of the matrix and 2d array called tiles.
    tiles[][] contains for example {{1, 1}, {1, 1}, {1, 1}, {1, 1}}, and the size of the matrix 2,2.
    now i need to take those details and check if the matrix contains the list of tiles , for this example is true because {1,1} is a one place in the matrix is like 1X1 , before the X is Height and after is Width. ( you can see in the image below).
    the function is :

    public static int[][] insertIntoKnapsack(int n, int m, int[][] tiles) {
    int[][] ans = new int[n][m];

    int H,W;
    for(int ind=0;ind<tiles.length;ind++)
    {
    H = tiles[ind][0];
    W = tiles[ind][1];


    now i stuck i dont know what do to check.
    any ideas?
    thanks.
    knapsack.jpg
    Last edited by ofirattia; December 8th, 2012 at 01:33 PM. Reason: more details


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Knapsack problem , check if matrix can fill list of smaller matrix list.

    What have you tried? Where are you stuck? Break the problem down into pieces, and give each piece a try. When you get stuck on a piece, ask a specific question about why you are stuck and provide all the information for us to help

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/66119-knapsack-problem-check-if-matrix-can-fill-list-smaller-matrix-list.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. problem of creating matrix with JButton or Panel
    By ms_ceng in forum AWT / Java Swing
    Replies: 3
    Last Post: December 16th, 2011, 04:53 PM
  2. Replies: 7
    Last Post: November 18th, 2011, 02:47 PM
  3. Matrix multiplication problem with different dimensions
    By mightyking in forum Collections and Generics
    Replies: 5
    Last Post: September 25th, 2011, 04:59 PM
  4. Having problem in matrix multiplication....
    By sidhant in forum Java Theory & Questions
    Replies: 5
    Last Post: March 17th, 2011, 01:41 PM
  5. Inverse of a Matrix problem
    By shivamchauhan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 17th, 2011, 01:40 PM

Tags for this Thread