###### usaco 2.1.4 Healthy Holsteins

surprise!

Healthy Holsteins

Farmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin content for one scoop of each feed type and the minimum daily vitamin requirement for the cows. Help Farmer John feed his cows so they stay healthy while minimizing the number of scoops that a cow is fed.

Given the daily requirements of each kind of vitamin that a cow needs, identify the smallest combination of scoops of feed a cow can be fed in order to meet at least the minimum vitamin requirements.

Vitamins are measured in integer units. Cows can be fed at most one scoop of any feed type. It is guaranteed that a solution exists for all contest input data.

### INPUT FORMAT

 Line 1: integer V (1 <= V <= 25), the number of types of vitamins Line 2: V integers (1 <= each one <= 1000), the minimum requirement for each of the V vitamins that a cow requires each day Line 3: integer G (1 <= G <= 15), the number of types of feeds available Lines 4..G+3: V integers (0 <= each one <= 1000), the amount of each vitamin that one scoop of this feed contains. The first line of these G lines describes feed #1; the second line describes feed #2; and so on.

### SAMPLE INPUT (file holstein.in)

4
100 200 300 400
3
50   50  50  50
200 300 200 300
900 150 389 399


### OUTPUT FORMAT

The output is a single line of output that contains:

• the minimum number of scoops a cow must eat, followed by:
• a SORTED list (from smallest to largest) of the feed types the cow is given
If more than one set of feedtypes yield a minimum of scoops, choose the set with the smallest feedtype numbers.

### SAMPLE OUTPUT (file holstein.out)

2 1 3


/*
ID: wtff0411
PROG: holstein
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
freopen("holstein.in","r",stdin);
freopen("holstein.out","w",stdout);
int v,g;
int i,j,k;
int r[100];
int s[50][50];

cin>>v;

for(i=0;i<v;i++)
cin>>r[i];
cin>>g;
for(i=0;i<g;i++)
for(j=0;j<v;j++)
cin>>s[i][j];
int m=pow(2.0,(double)g);
int resn=100,ress=1000000;
for(i=1;i<m;i++)
{
int tempr[100];
memset(tempr,0,sizeof(tempr));
int tempn=0;
int temp=i;
for(j=0;j<g;j++)
{
if(temp&1)
{
for(k=0;k<v;k++)
{
tempr[k]+=s[j][k];

}
tempn++;
}
if(tempn>resn)break;
temp=temp>>1;//aha shit
}

bool flag=false;
for(k=0;k<v;k++)
{
if(tempr[k]<r[k])
{ flag=true;
break;
}
}
//  cout<<tempn<<endl;
if(flag==false&&((tempn<resn)||((tempn==resn)&&(i<ress))))
{

resn=tempn;
ress=i;
}

}
cout<<resn;
for(j=1;j<=g;j++)
{
if(ress&1)
{
cout<<" "<<j;
}
ress=ress>>1;
}
cout<<endl;//well...- -that's it
//system("pause");
return 0;
}


#### JZOJ1260.【USACO题库】2.1.4 Healthy Holsteins健康的好斯坦奶牛

2017-04-01 14:45:43

#### USACO：2.1.4 Healthy Holsteins 健康的好斯坦奶牛

2015-01-23 22:07:18

#### [USACO 2.1.4] Healthy Holsteins

2011-12-15 16:37:56

#### Healthy Holsteins（USACO 2.1.4）

2015-09-25 20:34:37

#### USACO 2.1.4 Healthy Holsteins

2015-02-03 11:58:11

#### USACO 2.1.4 Healthy Holsteins解题报告

2013-07-29 16:48:26

#### USACO 2.1.4 Healthy Holsteins (DFS)

2014-04-05 20:15:36

#### USACO 2.1.4 Healthy Holsteins 健康的好斯坦奶牛 DFS & 组合

2013-08-07 16:22:37

#### 洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins

2016-11-10 18:13:26

#### 【题解】Healthy Holsteins

2016-02-15 15:09:11

## 不良信息举报

usaco 2.1.4 Healthy Holsteins