BZOJ-1042 [HAOI2008]硬币购物 容斥原理 +01背包方案数
2017-06-01 21:50
465 查看
大家都很强,可与之共勉。
[HAOI2008]硬币购物Description
硬币购物一共有4种硬币。面值分别为c1,c2,c3,c4。某人去商店买东西,去了tot次。每次带di枚ci硬币,买si的价值的东西。请问每次有多少种付款方法。
Input
第一行 c1,c2,c3,c4,tot 下面tot行 d1,d2,d3,d4,s,其中di,s<=100000,tot<=1000
Output
每次的方法数
Sample Input
1 2 5 10 2
3 2 3 1 10
1000 2 2 2 900
Sample Output
4
27
************************************************************** Problem: 1042 User: Lazer2001 Language: C++ Result: Accepted Time:40 ms Memory:1604 kb ****************************************************************/ #include <cstdio> unsigned int c[4], d[4], S, T; unsigned long long dp[100005] = {1}, ans; void Dfs ( short step, short flag, int sum ) { if ( sum < 0 ) return; if ( step == 4 ) { flag & 1 ? ans -= dp[sum] : ans += dp[sum]; return; } Dfs ( step + 1, flag, sum ); Dfs ( step + 1, flag ^ 1, sum - ( d[step] + 1 ) * c[step] ); } int main ( ) { for ( int i = 0; i < 4; ++i ) scanf ( "%d", c + i ); for ( int i = 0; i < 4; ++i ) for ( int j = c[i]; j <= 100000; ++j ) dp[j] += dp[j - c[i]]; for ( scanf ( "%d", &T ); T; --T ) { for ( int i = 0; i < 4; ++i ) scanf ( "%d", d + i ); scanf ( "%d", &S ); ans = 0; Dfs ( 0, 0, S ); printf ( "%lld\n", ans ); } }
相关文章推荐
- Bzoj 1042: [HAOI2008]硬币购物 容斥原理,动态规划,背包dp
- 【bzoj1042】 HAOI2008硬币购物 容斥原理+背包dp
- BZOJ 1042 HAOI2008 硬币购物 背包+容斥原理
- [BZOJ 1042][HAOI 2008]硬币购物(背包+容斥原理)
- [bzoj 1042][HAOI2008]硬币购物(用容斥原理弄背包)
- BZOJ 1042:[HAOI2008]硬币购物 容斥原理 背包dp
- BZOJ 1042: [HAOI2008]硬币购物( 背包dp + 容斥原理 )
- BZOJ_1042_[HAOI2008]硬币购物_容斥原理+背包
- BZOJ 1042: [HAOI2008]硬币购物(容斥原理)
- [bzoj1042][HAOI2008]硬币购物 容斥原理
- [BZOJ1042][HAOI2008]硬币购物-容斥原理
- [BZOJ1042][HAOI2008]硬币购物(背包+容斥)
- 【bzoj1042】[HAOI2008]硬币购物 背包dp+容斥原理
- [BZOJ 1042][HAOI2008]硬币购物:容斥原理
- [容斥原理]Bzoj1042 硬币购物[HAOI2008]
- BZOJ 1042 [HAOI2008]硬币购物 容斥原理
- BZOJ 1042 HAOI 2008 硬币购物 容斥原理
- BZOJ1042 [HAOI2008]硬币购物 【完全背包 + 容斥】
- 【BZOJ1042】[HAOI2008]硬币购物【计数DP】【容斥原理】
- BZOJ1042 [HAOI2008]硬币购物 【完全背包 + 容斥】