Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- int n,i,j,s[10]={0},b[10]={0},k,l,t;
- long int totals,totalb,min=1000000001;
- char bit[32]={'0'};
- scanf("%d",&n);
- for(i=0;i<n;i++) scanf("%d %d",&s[i],&b[i]);
- k=pow(2,n);
- for(i=1;i<k;i++)
- {
- //printf("\n");
- totals=1;
- totalb=0;
- l=0;
- t=i;
- do
- {
- bit[l++]=(t%2)+'0';
- t/=2;
- }
- while(t>0);
- //printf("l = %d ",l-1);
- for(t=l-1;t>=0;t--)
- {
- //printf("%c",bit[t]);
- if(bit[t]=='1')
- {
- totals*=s[t];
- totalb+=b[t];
- bit[t]='0';
- }
- }
- t=abs(totals-totalb);
- if(t==0)
- {
- printf("0");
- return 0;
- }
- if(t<min) min=t;
- }
- printf("%d",min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement