Time Limits: 1000 ms Memory Limits: 65536 KB Detailed Limits
1 #include <stdio.h> 2 #include <math.h> 3 #include <iostream> 4 using namespace std; 5 int x[11],y[11],b[11]; 6 int n,ans=1<<31-1; 7 void dfs(int u,int v) 8 { 9 ans=abs(u-v)<ans?abs(u-v):ans; 10 for (int j=1;j<=n;j++) 11 if (!b[j]) 12 { 13 b[j]=1; 14 dfs(u*x[j],v+y[j]); 15 b[j]=0; 16 } 17 } 18 int main() 19 { 20 cin>>n; 21 for (int i=1;i<=n;i++) 22 cin>>x[i]>>y[i]; 23 for (int i=1;i<=n;i++) 24 { 25 b[i]=1; 26 dfs(x[i],y[i]); 27 b[i]=0; 28 } 29 cout<<ans; 30 }