#P4141. 消失之物

    ID: 3077 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划,dp递推枚举,暴力分治背包

消失之物

Description

ftiasch has nn items with volumes w1,w2,,wnw_1,w_2,\dots,w_n. Due to her negligence, the ii-th item is missing.

“How many ways are there to exactly fill a knapsack of capacity xx using the remaining n1n-1 items?” — this is a classic problem.

She records the answer as cnt(i,x)\text{cnt}(i,x) and wants the table of cnt(i,x)\text{cnt}(i,x) for all i[1,n]i \in [1,n] and x[1,m]x \in [1,m].

Input Format

The first line contains two integers n,mn,m, the number of items and the maximum capacity.
The second line contains nn integers w1,w2,,wnw_1,w_2,\dots,w_n, the volume of each item.

Output Format

Output an n×mn \times m matrix, giving the last digit of cnt(i,x)\text{cnt}(i,x).

3 2
1 1 2
11
11
21

Hint

Constraints
For 100%100\% of the testdata, 1n,m20001 \le n,m \le 2000, and 1wi20001 \le w_i \le 2000.

Sample explanation
If item 33 is missing, there is exactly one way to fill capacity 22, namely choosing items 11 and 22.


upd 2023.8.11\text{upd 2023.8.11}: Added five new hack test sets.

Translated by ChatGPT 5