AcWing 281. 硬币
原题链接
困难
作者:
橙柚哥哥
,
2024-06-11 17:22:57
,
所有人可见
,
阅读 5
求赞!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=110,M=1e5+10;
ll n,m,a[N],g[M];
bool dp[M];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>n>>m,n || m) {
for(ll i=1; i<=n; i++) cin>>a[i];
memset(dp,0,sizeof(dp));
dp[0]=1;
for(ll i=1,c; i<=n; i++) {
cin>>c;
memset(g,0,sizeof(g));
for(ll j=a[i]; j<=m; j++)
if(!dp[j] && dp[j-a[i]] && g[j-a[i]]<c) {
dp[j]=1;
g[j]=g[j-a[i]]+1;
}
}
ll ans=0;
for(ll i=1; i<=m; i++) ans+=dp[i];
cout<<ans<<"\n";
}
return 0;
}