Comment

avatar username

It can be proved that while adding new numbers in the knapsack, the minimum number $s$ that cannot be formed is monotonically non-decreasing, because all numbers from $1\sim s-1$ can be formed by the original knapsack and will not be affected by the numbers put in.

Let $f_i$ be $1$ if $i$ can be formed and $0$ if can't.

After adding a new number $s$ in the knapsack and updating the array $f$(for $i=n,n-1,\dots,s$ let $f_i=\max(f_i,f_{i-s})$), iterate $x=s,s+1,\dots$ until $f_x=0$. Thus $x$ is the smallest number that cannot be formed.

In this problem, you need to ignore $f_k$ when iterating $x$.

The actual rating of this user is 2286.

Original comment.

Statistics