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,cnt;
- 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=20000000;
- ps=pow(2,n);
- for(i=0;i<ps-1;i++){
- temto=0;
- cnt=0;
- for(j=0;j<n;j++){
- if(i&(1<<j)){
- temto=temto+w[j];
- }
- }
- diff=total-temto;
- diff=temto-diff;
- if(diff<0)
- diff=-diff;
- if(min>diff)
- min=diff;
- }
- printf("%d\n",min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement