Color the bricks
Practice
4 (11 votes)
2 D array
Algorithms
Dynamic programming
Easy
Problem
51% Success 1305 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given \(N\) bricks that are numbered from \(1\) to \(N\). You are required to color all the bricks. Here, \(K\) bricks are already colored.

You can only color the \(i^{th}\) brick if the \((i+1)^{th}\) or \((i-1)^{th}\) brick is already colored. Your task is to determine the number of ways you can color all the remaining bricks. Since the number of ways can be very large, therefore print the number of ways modulo \(1000000007\).
Input format

  • First line: Two space-separated integer \(N,\ K\)
  • Second line: \(K\) space-separated integers each denoting the brick that is already colored

Output format

Print an integer denoting the number of ways to color the remaining bricks modulo \(1000000007\).

Constraints

\(1\le K\le N\le1000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
12 votes
Tags:
CombinatoricsMathematicsDynamic Programming2D dynamic programmingAlgorithms
Points:30
5 votes
Tags:
AlgorithmsDynamic ProgrammingEasyOpenTwo dimensional
Points:30
8 votes
Tags:
AlgorithmsDynamic Programming2D dynamic programming