Advertisement
erfanul007

timus 1005

Dec 3rd, 2018
168
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.  
  4. int main()
  5. {
  6. int n,w[30],i,j;
  7. int total=0,ps,temto,diff,min;
  8. scanf("%d",&n);
  9. for(i=0;i<n;i++){
  10. scanf("%d",&w[i]);
  11. total=total+w[i];
  12. }
  13. min=9000000;
  14. ps=pow(2,n);
  15. for(i=0;i<ps-1;i++){
  16. temto=0;
  17. for(j=0;j<n;j++){
  18. if(i&(1<<j)){
  19. temto=temto+w[j];
  20. }
  21. }
  22. diff=total-temto;
  23. diff=abs(temto-diff);
  24. if(min>diff)
  25. min=diff;
  26. }
  27. printf("%d\n",min);
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement