ofir attia

Greenhorn

Posts: 1

posted 5 years ago

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.

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.

posted 5 years ago

Welcome to CodeRanch!

Wikipedia describers a few algorithms you can use to accomplish this. Read that and then come back with specific questions. Ideally after you have a little code and are stuck.

Wikipedia describers a few algorithms you can use to accomplish this. Read that and then come back with specific questions. Ideally after you have a little code and are stuck.

[OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]

Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2

Consider Paul's rocket mass heater. |