Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int n,w[30],i,j;
- int total=0,ps,temto,diff,min;
- scanf("%d",&n);
- for(i=0;i<n;i++){
- scanf("%d",&w[i]);
- total=total+w[i];
- }
- min=9000000;
- ps=pow(2,n);
- for(i=0;i<ps-1;i++){
- temto=0;
- for(j=0;j<n;j++){
- if(i&(1<<j)){
- temto=temto+w[j];
- }
- }
- diff=total-temto;
- diff=abs(temto-diff);
- if(min>diff)
- min=diff;
- }
- printf("%d\n",min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement