Can you please explain why you did
pwr(fact[x], mod - 2))%mod
Lets try to come up with a recursion for the above DP state. Assume w[i] > w
Is the following recursion correct?
best[i][w] = max(best[i-1][w], best[i-1][w-w[i]] + v[i])
The answer is YES but shouldn't it be NO since "w[i] > w" so we can't reduce it from w since it will lead to -ve total weight