Bzoj1042: [HAOI2008]硬币购物
2018-03-27 20:42
441 查看
题面
传送门Sol
容斥原理+背包处理出所有金币无限制条件凑成jj元的方案数
考虑计算
cc只有44种,可以容斥一波
就是无限制的总方案-11个硬币超出限制的方案+22个的-33个的+44个的
# include <bits/stdc++.h> # define RG register # define IL inline # define Fill(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; const int _(1005); IL int Input(){ RG int x = 0, z = 1; RG char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1; for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * z; } typedef int Arr[_]; int c[4], tot, mx, pw[4] = {1, 2, 4, 8}, s[_], d[4][_]; ll f[_ * 100] = {1}, ans; int main(RG int argc, RG char *argv[]){ for(RG int i = 0; i < 4; ++i) c[i] = Input(); tot = Input(); for(RG int i = 1; i <= tot; ++i){ for(RG int j = 0; j < 4; ++j) d[j][i] = (Input() + 1) * c[j]; s[i] = Input(), mx = max(mx, s[i]); } for(RG int i = 0; i < 4; ++i) for(RG int j = c[i]; j <= mx; ++j) f[j] += f[j - c[i]]; for(RG int i = 1; i <= tot; ++i){ ans = 0; for(RG int j = 0; j < 16; ++j){ RG int op = 1, sum = 0; for(RG int k = 0; k < 4; ++k) if(j & pw[k]) op = -op, sum += d[k][i]; ans += (sum > s[i]) ? 0 : (1LL * op * f[s[i] - sum]); } printf("%lld\n", ans); } return 0; }
相关文章推荐
- 【bzoj】1042: [HAOI2008]硬币购物
- bzoj1042: [HAOI2008]硬币购物
- bzoj1042: [HAOI2008]硬币购物(DP+容斥)
- 【bzoj 1042】 [HAOI2008] 硬币购物(dp+容斥原理)
- BZOJ1042: [HAOI2008]硬币购物
- BZOJ1042: [HAOI2008]硬币购物
- [容斥原理]Bzoj1042 硬币购物[HAOI2008]
- [HAOI2008][BZOJ1042] 硬币购物
- BZOJ 1042: [HAOI2008]硬币购物 容斥+背包
- bzoj 1042 [HAOI2008]硬币购物
- bzoj1042[HAOI2008]硬币购物
- bzoj 1042: [HAOI2008]硬币购物
- BZOJ 1042 [HAOI2008]硬币购物 - 容斥+DP
- 【bzoj1042】[HAOI2008]硬币购物
- BZOJ 1042 [HAOI2008]硬币购物 容斥原理
- bzoj 1042: [HAOI2008]硬币购物(dp+容斥)
- BZOJ1042: [HAOI2008]硬币购物
- bzoj 1042: [HAOI2008]硬币购物【容斥原理+dp】
- BZOJ 1042: [HAOI2008]硬币购物
- BZOJ 1042: [HAOI2008]硬币购物【容斥】【01背包】