Barcode

3.9

12 votes
Dynamic Programming, Combinatorics, Easy-Medium, Ready, Mathematics, Open, Approved
Problem

You have n-strip colorless bar code, where each strip is of unit length. You are given k brushes having their own different width. Using a brush of width w you can paint at a time exactly w consecutive strips on a bar code with black color, with the condition that initially all those w strips should be colorless. You can use any brush infinite times.

Find the number of distinct bar codes that you can create. Two bar codes are considered different if there exists at least one strip that is black in first and colorless in other. Print your answer modulo 109+7.

Input:

First line of input contains two space separated integers n and k denoting number of strips on bar code and number of brushes respectively. Next line contains k space separated integers, the ith integer denoting the width of ith brush.

Output:

Output in single line, your answer modulo 109+7.

Constraints:

1 ≤ n , k ≤ 103
1 ≤ width of ith brush (wi) ≤ 103

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here are the possible bar codes that you can generate on strip of size 3 and brush of width 1. (0-white, 1-black)

000 001 010 100 011 101 110 111

Hence answer is 8.

Editor Image

?