HDU 1709 the Balance

Source: Internet
Author: User

Description

Now is asked to measure a dose of medicine with a balance and a number of weights. Certainly it isn't always achievable. So-should find out the qualities which cannot is measured from the range [1,s]. S is the total quality of the weights.

Input

The input consists of multiple test cases, and each case begins with a single positive integer N (1<=n<=100) on a Li NE by itself indicating the number of weights. followed by N integers Ai (1<=i<=n), indicating the quality of each weight where 1<=ai<=100.

Output

For each input set, you should first print a line specifying the number of qualities which cannot is measured. Then print another line which consists all the irrealizable qualities if the number was not zero.

Sample Input

3 1 2 4 3 9 2 1

Sample Output

0 2 4 5 test instructions: Test instructions: Given the weight of n weights, the total mass is sum, asking how many weights in the 1~sum cannot be weighed. Each weight can be placed on the right disk, and can be placed on the left disk, (if the left thing right code), put in the left disk then take minus, put on the right side to take the plus. is to apply the code equation for the 01 backpack:
C[j]|= b[j]; C "", B "", there is a case for 1 to be established without adding a "" Situation if (J+a< Span class= "Sh-symbol" >[i]<=sum) c[j< Span class= "Sh-symbol" >+a[i]]+=b[j//plus a "" C[(intabs (J-a[i[j]; Two weight difference                
#include <cstdio>#include<cstring>#include<cmath>using namespacestd;intMain () {intt,a[ the],i,j,sum; intb[10005],c[10005];  while(SCANF ("%d", &t)!=-1) {sum=0;  for(i=1; i<=t;i++) {scanf ("%d",&A[i]); Sum+=A[i]; } memset (b,0,sizeof(b)); Memset (c,0,sizeof(c)); b[0]=1; b[a[1]]=1;  for(i=2; i<=t;i++)       {            for(j=0; j<=sum;j++) {C[j]|= B[j];//C "", B "", there is a case for 1 to be established without adding a ""               if(j+a[i]<=sum) c[j+A[I]]+=B[J];//plus a ""c[(int) ABS (J-a[i])]+=b[j];//the difference of two weights} memcpy (B,c,sizeof(c)); Memset (c,0,sizeof(c)); } J=0;  for(i=1; i<=sum;i++)           if(b[i]==0) C[j++]=i; printf ("%d\n", J); if(j) {printf ("%d", c[0]);  for(i=1; i<j;i++) printf ("%d", C[i]); printf ("\ n"); }   }   return 0;}
View Code

HDU 1709 the Balance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.