PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000046. Tổ hợp tiền xu II (Coin Combinations II)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổ hợp tiền xu II (Coin Combinations II)
Coin Combinations II
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A currency system has distinct positive denominations, with an unlimited supply of each type. Count the number of ways to choose how many coins of each denomination sum to exactly . Order does not matter: a choice is determined solely by its counts for each denomination. Report the result modulo .
Input
The first line contains and . The next line contains the distinct denominations .
Output
Print the number of combinations modulo .
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , , all distinct.
- Subtask 2 (30%): , , , all distinct.
- Subtask 3 (50%): , , , all distinct.
Examples
Input
3 9
2 3 5
Output
3
Explanation
There are exactly multisets of coins: , and . Reordering coins does not create another way.