容斥
#include<bits/stdc++.h> #define N 100005 typedef long long ll; using namespace std; ll ans,f[N]; int c[10],d[10],T; void dfs(int x,int k,int sum){ if(sum<0)return; if(x==5){ if(k&1)ans-=f[sum]; else ans+=f[sum]; return ; } dfs(x+1,k+1,sum-(d[x]+1)*c[x]); dfs(x+1,k,sum); } inline int read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int main(){ for(int i=1;i<=4;i++)c[i]=read(); T=read();f[0]=1; for(int i=1;i<=4;i++)for(int j=c[i];j<=100000;j++)f[j]+=f[j-c[i]]; while(T--){ for(int i=1;i<=4;i++)d[i]=read(); int x=read();ans=0; dfs(1,0,x); printf("%lld ",ans); } return 0; }