Advertisement
erfanul007

Untitled

Dec 3rd, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int n,w[30],i,j;
  6. int total=0,ps,temto,diff,min;
  7. scanf("%d",&n);
  8. for(i=0;i<n;i++){
  9. scanf("%d",&w[i]);
  10. total=total+w[i];
  11. }
  12. min=9000000;
  13. ps=pow(2,n);
  14. for(i=1;i<ps-1;i++){
  15. temto=0;
  16. for(j=0;j<n;j++){
  17. if(i&(1<<j)){
  18. temto=temto+w[j];
  19. }
  20. }
  21. diff=total-temto;
  22. diff=abs(temto-diff);
  23. if(min>diff)
  24. min=diff;
  25. }
  26. printf("%d\n",min);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement