#includeint c1,c2;int n;int w[1000]={0};int s[1000]={0};int tmp=1;int sum=0;bool end[1000]={0};int q=0;int f(int tmp); int is();int main(){int i,j;while(1){scanf("%d %d %d",&c1,&c2,&n);q=q+1;if(c1==0&&c2==0&&n==0){q=q-1;break;}for(i=1;i <= n;i++){scanf("%d",&w[i]);}sum=0;for(i = 1; i <= n ;i++){sum=sum+w[i];}f(1);}for(i=1;i <= q;i++){if(end[i] == 1){printf("Yes\n");}else{printf("No\n");}}return 0;} int f(int tmp){int i;if(tmp == n+1){if(is()){end[q]=1;}return 0;}for(i=0; i<=1 ; i++){s[tmp]=i;f(tmp+1);}return 0;}int is(){int i,j;int sum1,sum2;sum1=0;sum2=0;for(i=1;i<=n;i++){sum1=sum1+s[i]*w[i];}if(sum1 <= c1 && sum - sum1 <= c2){return 1;}return 0;}
装载问题
最新推荐文章于 2020-07-13 20:33:26 发布