루미 알고리즘

#1298골드The Gourmet

PO 2010 온라인 예선코딩영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

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 ≤ M ≤ 1000), the number of minutes.

The second line contains an integer N (1 ≤ N ≤ 30), the number of courses.

Afterwards, N lines follow with an integer T_i (1 ≤ T_i ≤ 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 (2000000000).

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.

GroupPoint valueConstraints
160The answer will be less than 2 million (2000000).
240No additional constraints.

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 servings = 9 minutes) or too late (4 servings = 12 minutes).

예제

예제 1

입력
10
2
7
3
출력
2

예제 2

입력
12
6
1
3
3
5
6
12
출력
498

출처 표기

출처: Programmeringsolympiaden 2010년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.