## 1042: [HAOI2008]硬币购物

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1706  Solved: 985
[Submit][Status][Discuss]

1 2 5 10 2
3 2 3 1 10
1000 2 2 2 900

## Sample Output

4
27

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int a[4], b[4], s;
ll dp[100005];
ll solve() {
ll ret = 0;
for(int i = 0; i<(1<<4); i++) {
int cnt = 0, sum = s;
for(int j = 0; j<4; j++) {
if((1<<j)&i) {
cnt++;
sum -= a[j]*(b[j]+1);
}
}
if(sum<0)
continue;
if(cnt&1) {
ret -= dp[sum];
} else {
ret += dp[sum];
}
}
return ret;
}
int main()
{
for(int i = 0; i<4; i++) {
scanf("%d", &a[i]);
}
int n;
cin>>n;
dp[0] = 1;
for(int i = 0; i<4; i++) {
for(int j = a[i]; j<=100000; j++) {
dp[j] += dp[j-a[i]];
}
}
for(int i = 0; i<n; i++) {
for(int j = 0; j<4; j++) {
scanf("%d", &b[j]);
}
scanf("%d", &s);
cout<<solve()<<endl;;
}
return 0;
}

posted on 2016-02-28 15:09  yohaha  阅读(188)  评论(0编辑  收藏  举报