Advertisement
erfanul007

stone pile wa

Dec 3rd, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int n,w[30],i,j,cnt;
  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=20000000;
  13. ps=pow(2,n);
  14. for(i=0;i<ps-1;i++){
  15. temto=0;
  16. cnt=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=temto-diff;
  24. if(diff<0)
  25. diff=-diff;
  26. if(min>diff)
  27. min=diff;
  28. }
  29. printf("%d\n",min);
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement