# Knapsack ,check if matrix can fill list of smaller matrix list

Page 1 of 1

## 0 Replies - 4018 Views - Last Post: 08 December 2012 - 11:42 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303219&amp;s=2f402ca5745580c61d23d5a4004650ad&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ofirattia

Reputation: 0
• Posts: 1
• Joined: 08-December 12

# Knapsack ,check if matrix can fill list of smaller matrix list

Posted 08 December 2012 - 11:42 AM

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.

This post has been edited by Atli: 08 December 2012 - 12:19 PM
Reason for edit:: Use [code] tags when posting code.

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}