Chimichangas
시간 제한0.35초메모리 제한1024 MB
정확히 K개의 chimichanga 종류를 순서대로 골라 칼로리 합이 각 질의 값이 되는 경우의 수를 2999로 나눈 나머지로 구한다. 합이 1e9까지 커지므로 모듈로 2999의 주기성을 이용해야 한다.
문제
Being tired of shooting his huge upcoming movie, Deadpool has decided to take a short break and open a restaurant in Canada. Deadpool is also the chef and he can only cook one type of food: chimichangas. For those of you who don't know what chimichangas are (shame on you!), think of a fried burrito.
Deadpool can cook N unique types of chimichangas, each of them having a precise number of calories (Deadpool doesn't make mistakes). All the chimichangas have at most C calories.
The restaurant has become very popular. Today there are Q clients in line and Deadpool wants to impress them.
Each client eats a K-course meal (K dishes), follows a very strict diet and knows exactly how many calories they are supposed to eat. Client i eats exactly meali calories. Each client would like to know in how many ways they can achieve the amount of calories their diet requires by eating exactly K chimichangas (not necessarily of distinct types).
Given the calorie contents of N types of chimichangas (calorie1, calorie2, …, calorieN), as well as the number of courses K, you must answer Q questions, one for every client's calorie requirement.
입력
The input has the format:
line 1: N K
line 2: calorie1 calorie2 ... calorieN
line 3: Q
line 4 ... Q + 3: meal1
meal2
...
mealQ
출력
The output must contain Q lines. Each line must contain a single number, the answer to the corresponding question. Because the answer can be big, you are asked to compute it modulo 2999.
제한
- 1 ≤ caloriei ≤ C for 1 ≤ i ≤ N
- 0 ≤ meali ≤ W for 1 ≤ i ≤ Q
- 1 ≤ C × K ≤ 100,000
- 1 ≤ N ≤ C
- 0 ≤ W ≤ 1,000,000,000
- 1 ≤ Q ≤ 200,000
- Deadpool has an infinite amount of each type of chimichanga.
- The order in which each client eats matters (e.g. (1 + 2) is different from (2 + 1))
- No two types of chimichanga have the same number of calories.
- The answers must be printed modulo 2999.
힌트
There are 4 ways to eat 5 calories: (1 + 1 + 1 + 2), (1 + 1 + 2 + 1), (1 + 2 + 1 + 1), (2 + 1 + 1 + 1).
There is 1 way to eat 4 calories: (1 + 1 + 1 + 1).
There are 5 ways to eat 8 calories: (1 + 1 + 1 + 5), (1 + 1 + 5 + 1), (1 + 5 + 1 + 1), (5 + 1 + 1 + 1), (2 + 2 + 2 + 2).