洛谷 P1450 [HAOI2008] 硬币购物
https://www.luogu.com.cn/problem/P1450
问题等价于 \(c_1x_1 + c_2x_2 + c_3x_3 + c_4x_4 = s,\ x_i \le d_i\) 有多少组解。考虑容斥,强制使 \(x_i \ge d_i + 1\) 等价于 \(s \gets s - c_i(d_i + 1),\ x_i \ge 0\),因此预处理出 \(f_{sum}\) 为 \(c_1x_1 + c_2x_2 + c_3x_3 + c_4x_4 = sum,\ x_i \ge 0\) 的解数即可。

浙公网安备 33010602011771号