AC

许诺  •  1个月前


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std; typedef long long ll; const int MAXS = 100010; int c[5], n; ll f[MAXS]; void preprocess() {

f[0] = 1;
for (int i = 1; i <= 4; i++) {
    for (int j = c[i]; j < MAXS; j++) {
        f[j] += f[j - c[i]];
    }
}

} ll calculate(int d1, int d2, int d3, int d4, int s) {

ll res = 0;
for (int mask = 0; mask < 16; mask++) {
    int cnt = 0;
    ll rem = s;
    if (mask & 1) rem -= (d1 + 1) * c[1], cnt++;
    if (mask & 2) rem -= (d2 + 1) * c[2], cnt++;
    if (mask & 4) rem -= (d3 + 1) * c[3], cnt++;
    if (mask & 8) rem -= (d4 + 1) * c[4], cnt++;
    if (rem < 0) continue;
    if (cnt % 2 == 0) res += f[rem];
    else res -= f[rem];
}
return res;

} int main() {

cin >> c[1] >> c[2] >> c[3] >> c[4] >> n;
preprocess();
while (n--) {
    int d1, d2, d3, d4, s;
    cin >> d1 >> d2 >> d3 >> d4 >> s;
    ll ans = calculate(d1, d2, d3, d4, s);
    cout << ans << endl;
}
return 0;

}


评论:

请先登录,才能进行评论