全站首A
2025-08-04 16:10:39
发布于:上海
8阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll dp[N],c[10],d[10];
void dfs(int pos,int num,ll sum,ll &ans){
if(pos==5){
if(sum>=0)ans+=(num%2?-1:1)*dp[sum];
return;
}
dfs(pos+1,num+1,sum-c[pos]*(d[pos]+1),ans);
dfs(pos+1,num,sum,ans);
}
int main() {
int n;
for(int i=1;i<=4;i++)cin>>c[i];
cin>>n;
dp[0]=1;
for(int i=1;i<=4;i++){
for(int j=c[i];j<N;j++){
dp[j]+=dp[j-c[i]];
}
}
while(n--){
ll s,ans=0;
for(int i=1;i<=4;i++){
cin>>d[i];
}
cin>>s;
dfs(1,0,s,ans);
cout<<ans<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个