top of page
Caută
Poza scriitoruluioanaunciuleanu

Tiling Problem in JAVA

You can use a board that is 2 x n size. The tiles are of size 2 x 1. Count the number of ways to tile the board. Tiles can be placed vertically 2 x 1 or horizontally as 1 x 2.


Input: int board = 4; Output: 5 Explanation: For a 2 x 4 board there are 5 ways to tile: 1 way is with all tiles vertical, 1 way is with all horizontal, and 3 ways having the 4 tiles displayed 2 vertical and 2 horizontal.



Solution:


1. static int getNoOfWaysToTile(int board) { 2. if (board <= 2) { 3. return board; 4. } 5. return getNoOfWaysToTile(board - 1) + getNoOfWaysToTile(board - 2); 6. } 7.


6 afișări0 comentarii

Postări recente

Afișează-le pe toate

Subset Sum Problem in JAVA

Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with the sum equal to the given...

Comments


bottom of page