- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to count number of horizontal brick pattern can be made from set of bricks in Python

Suppose we have a list of numbers called bricks and two other values width and height. Each element in bricks[i] represents a brick whose length is bricks[i] units and width is 1 unit. We have to find the number of ways to lay the bricks such that we get full layout of bricks with the given width and height. We can reuse the bricks but can only be laid horizontally.

So, if the input is like bricks = [2, 1] width = 3 height = 2, then the output will be 9 because −

To solve this, we will follow these steps −

- w := a list of size same as width and insert 1 at first position, rest are 0
- for i in range 0 to width, do
- if w[i] is non-zero, then
- for each x in bricks, do
- if i + x <= width, then
- w[i + x] := w[i + x] + w[i]

- if i + x <= width, then

- for each x in bricks, do

- if w[i] is non-zero, then
- return w[width]^height

## Example

Let us see the following implementation to get better understanding −

def solve(bricks, width, height): w = [1] + [0] * width for i in range(width): if w[i]: for x in bricks: if i + x <= width: w[i + x] += w[i] return w[width] ** height bricks = [2, 1] width = 3 height = 2 print(solve(bricks, width, height))

## Input

[2, 1], 3, 2

## Output

9

- Related Questions & Answers
- C++ program to find number of groups can be formed from set of programmers
- C++ program to find out the number of coordinate pairs that can be made
- Program to count number of palindromes of size k can be formed from the given string characters in Python
- C++ code to count maximum groups can be made
- Program to count number of words we can generate from matrix of letters in Python
- C++ program to count number of problems can be solved from left or right end of list
- Count of numbers which can be made power of 2 by given operation in C++
- Program to find minimum number of bricks required to make k towers of same height in Python
- C++ Program to count number of teams can be formed for coding challenge
- C++ Program to find out the maximum amount of money that can be made from selling cars
- Program to find the length of the longest, that can be made using given letters in Python
- Program to find maximum score of brick removal game in Python
- C++ code to count number of times stones can be given
- Python program to count number of vowels using set in a given string
- C++ program to count maximum possible division can be made in a graph with given condition

Advertisements