JZOJ 1420. dishes

Time Limits: 1000 ms  Memory Limits: 65536 KB  Detailed Limits 

Description

  Food is very tasty dish of meaning, food is the most important to choose a good raw material.
  There are N kinds of ingredients, each of both acidity and S B Bitterness two attributes, when selecting a variety of materials, a total acidity of the acidity of the product of each ingredient, the total degree of bitterness Bitterness of each ingredient with.
  As you know, neither food nor bitter acid, as a raw material to ensure that the selected total acidity and total pain of the minimum absolute difference.
  Because food is not only water, so you must select at least one meal.

Input

  Input of the first row contains an integer N (1 <= N <= 10), indicates the number of kinds of raw materials.
  Next N lines contains two integers separated by a space, respectively, of the acidity and bitter.
  If the input data to ensure that all the raw materials are selected, total acidity and total pain of no more than 10 ^ 9.

Output

  Minimum difference between the total acidity and total output of bitter.

Sample Input

Input 1: 
1 
3 10 

Input 2: 
2 
3. 8 
. 5. 8 

input 3: 
. 4 
1. 7 
2. 6 
3. 8 
. 4. 9

Sample Output

Output 1: 
7 

Output 2: 
1 

Output 3: 
1

Data Constraint

Hint

[Explain] Sample
  Sample 3. Select the last three raw materials, so that the total acidity of 2 × 3 × 4 = 24, a total degree of bitter 6 + 8 + 9 = 23, the difference is 1.
 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 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11297615.html