hdu 2844 多重背包二进制优化
//http://www.cnblogs.com/devil-91/archive/2012/05/16/2502710.html
#include<stdio.h>
#define N 110000#include<string.h>
int dp[N];
int main() {
int n,m,i,j,a[N],b[N],k,h;
while(scanf("%d%d",&n,&m),n||m) {
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
dp[0]=1;
for(i=1;i<=n;i++) {
if(b[i]*a[i]>=m) {
for(j=a[i];j<=m;j++) {
if(dp[j-a[i]]==0)continue;
dp[j]=1;
}
}
else {
k=b[i];
h=1;
while(k>=h) {
for(j=m;j>=h*a[i];j--) {
if(dp[j-h*a[i]]==0)continue;
dp[j]=1;
}
k-=h;h*=2;
}
if(k>0) {
for(j=m;j>=k*a[i];j--) {
if(dp[j-k*a[i]]==0)continue;
dp[j]=1;
}
}
}
}
j=0;
for(i=1;i<=m;i++)
if(dp[i]==1)
j++;
printf("%d\n",j);
}
return 0;
}