#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int c[5], d[5], s, T;
ll f[maxn], ans;
int main()
{
for(int i = 1; i <= 4; i++) scanf("%d", &c[i]);
f[0] = 1;
for(int i = 1; i <= 4; i++)
for(int j = c[i]; j <= maxn-5; j++)
f[j] += f[j-c[i]];
scanf("%d", &T);
while(T--)
{
ll ans = 0;
for(int i = 1; i <= 4; i++)
scanf("%d", &d[i]);
scanf("%d", &s);
ans = f[s];
for(int i = 1; i < (1<<4); i++)
{
ll tmp = 0, num = 0;
for(int j = 1; j <= 4; j++)
{
if((1<<(j-1))&i)
{
num++;
tmp += (d[j]+1) * c[j];
}
}
if(tmp > s) continue;
if(num % 2 == 0) ans += f[s-tmp];
else ans -= f[s-tmp];
}
cout << ans << endl;
}
return 0;
}
原文:https://www.cnblogs.com/zxytxdy/p/12063893.html