背包求解的一道题目;
注意初始化。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<stdlib.h>
#define INT_MAX 0x7fffffff
#define INF 999999
#define max3(a,b,c) (max(a,b)>c?max(a,b):c)
#define min3(a,b,c) (min(a,b)<c?min(a,b):c)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
struct node
{int u;int v;int w;bool friend operator < (node a, node b){return a.w < b.w;}
}edge[1001];
int gcd(int n,int m){if(n<m) swap(n,m);return n%m==0?m:gcd(m,n%m);}
int lcm(int n,int m){if(n<m) swap(n,m);return n/gcd(n,m)*m;}
int dp[100001];
int c[1001];
int w[1001];
int sum;
int main()
{int n,i,j;int num[100001];while(scanf("%d%d",&n,&sum)&&(n||sum)){for(i=1;i<=n;i++)scanf("%d",&c[i]);for(i=1;i<=n;i++)scanf("%d",&w[i]);memset(dp,0,sizeof(dp));dp[0]=1;int ans=0;for(i=1;i<=n;i++){mem(num,0);for(j=c[i];j<=sum;j++){if(dp[j]!=1&&dp[j-c[i]]==1&&num[j-c[i]]<w[i]){ans++;num[j]=num[j-c[i]]+1;dp[j]=1;}}}printf("%d\n",ans);}return 0;
}