The Balance
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6652 Accepted Submission (s): 2730
Problem Descriptionnow You 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.
Inputthe input consists of multiple test cases, and each case begins with a single positive integer N (1<=n<=100) on A line 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.
Outputfor 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 Input31 2 439 2 1
Sample Output024 5
Source HDU 2007-spring Programming Contest
Recommendlcy | We have carefully selected several similar problems for you:2152 2069 2082 1721 1792
#include <stdio.h>#include<string.h>#include<math.h>intnum[10005];intans[10005];intc[10005],temp[10005];intMain () {intN; while(SCANF ("%d", &n)! =EOF) {memset (num,0,sizeof(num)); Memset (c,0,sizeof(c)); memset (ans,0,sizeof(ans)); memset (temp,0,sizeof(temp)); intTotal=0; for(intI=0; i<n;i++) {scanf ("%d",&Num[i]); Total+=Num[i]; } for(intI=0; i<=num[0];i+=num[0]) C[i]=1; for(intI=1; i<n;i++){ for(intj=0; j<=total;j++){ for(intk=0; k+j<=total&&k/num[i]<=1; k+=Num[i]) {///Note the =1 temp[j+k]+=C[j]; temp[(int) fabs (j-k)]+=c[j];//Note that negative values should be considered at this moment}} for(intIi=0; ii<=total;ii++) C[ii]=Temp[ii]; } intCnt=0; for(intI=1; i<=total;i++){ if(!C[i]) {CNT++; ANS[CNT]=i; }} printf ("%d\n", CNT); for(intI=1; i<=cnt;i++) {printf ("%d%c", ans[i],i==cnt?'\ n':' '); } } return 0;}
HDU 1709 Female function balance problem can be subtracted the Balance