题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2844
常数优化 ,不然TLE
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int val[100+5];
bool d[100000+5];
int main()
{int n,m,num;while(scanf("%d%d",&n,&m)!=EOF){if(n==0&&m==0) break;for(int i=0;i<n;i++)scanf("%d",&val[i]);memset(d,false,sizeof(d));d[0]=true; int cnt=0;for(int i=0;i<n;i++){scanf("%d",&num);int c=num,k=1;if(num*val[i]>m) { //加上这个可以快一半 for(int j=val[i];j<=m;j++)if(d[j-val[i]]&&d[j]==false) d[j]=true,cnt++;continue;}while(c>k){for(int j=m;j>=k*val[i];j--)if(d[j-k*val[i]]&&d[j]==false) d[j]=true,cnt++;c-=k; k<<=1;}for(int j=m;j>=c*val[i];j--)if(d[j-c*val[i]]&&d[j]==false) d[j]=true,cnt++;}cout<<cnt<<endl;}return 0;
}