Problem D
The Gourmet
Languages
en
sv
The French gourmet Frank is a very well-respected gourmet; his job involves going around to various restaurants, eating their food and then writing a review about the restaurant. But he carries a dark secret: he is actually only interested in eating as much as possible and in any order!
However, Frank understands that a true gourmet can’t eat in just any manner, like starting with his dessert and finishing with a salad. Therefore, he asks for your help in constructing a list with all the different ways he could arrange his courses during a meal, so that he can pick the best order.
During the serving, Frank has $M$ minutes to eat. The restaurant offers $N$ different courses, and he can eat any number of servings of each course. For course $i$, it takes $T_ i$ minutes to eat a serving of it. Frank wants to eat something during each of the $M$ minutes he has, and he wants to finish every course that he is served. He never wants to start eating a new course until he finished the last one.
Your task is to write a program to compute the number of ways he could arrange his meal, given these restrictions.
Input
The first line contains an integer $M$ ($1 \le M \le 1\, 000$), the number of minutes.
The second line contains an integer $N$ ($1 \le N \le 30$), the number of courses.
Afterwards, $N$ lines follow with an integer $T_ i$ ($1 \le T_ i \le 200$) on each line, the time it takes to eat every dish.
Output
The program should output the number of ways in which Frank can eat during exactly $M$ minutes.
The answer will always be at most 2 billion ($2\, 000\, 000\, 000$).
Scoring
Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.
Group |
Points |
Constraints |
$1$ |
$60$ |
The answer will be less than $2$ million ($2\, 000\, 000$). |
$2$ |
$40$ |
No additional constraints |
Scoring
Your program will be tested on $5$ test cases. For each test cases you pass, you will get $20$ points.
For test cases worth $60$ points, the answer will be less than $2$ million ($2\, 000\, 000$).
Explanation of Sample $1$
Frank is going to eat during $10$ minutes and have two courses to choose from, for example a salad (takes $3$ minutes to eat) and pie ($7$ minutes). There are only two ways he can eat them: first pie and then salad or vice versa. If he only eats salad he will either finish too quickly ($3 \text { servings} = 9 \text { minutes}$) or too late ($4 \text { servings} = 12 \text { minutes}$).
Sample Input 1 | Sample Output 1 |
---|---|
10 2 7 3 |
2 |
Sample Input 2 | Sample Output 2 |
---|---|
12 6 1 3 3 5 6 12 |
498 |