Title Description
Farmer John prides himself on having the healthiest cows in the world. He knows how much of the minimum amount of vitamins is needed for the cows contained in each feed. Please help the farmer to feed his cows to keep them healthy, so that the feed to the cows is given the fewest number of feeds.
Give the minimum amount of vitamin needed for a cow, and output the kind of feed you need to feed the cow with the least amount of feed needed.
The vitamins are expressed as integers, and each feed can only be used once for the cows, and the data is guaranteed to exist.
Input/output format
Input Format:
Line 1th: An integer V (1<=v<=25) that represents the number of vitamins needed.
Line 2nd: v integers (1<= per number <=1000), indicating the minimum amount of each vitamin that the cow needs each day.
Line 3rd: An integer G (1<=g<=15) that represents the number of feeds that can be used to feed cattle.
Below the G line, the nth line represents the amount of the various vitamins that are contained in the N feed.
output Format:
The output file has only one row, including
The minimum number of feed species required for cattle p
The number of P is followed, indicating the selected feed number (in order from small to large).
If there are multiple solutions, the output feed ordinal is the smallest (i.e. the dictionary order is the smallest).
Input/Output sample
Input Sample # #:
4100 400350 50200 300 200 300900 150 389 399
Sample # # of output:
2 1 3
Description
Usaco 2.1
Translation from Nocow
It's another dairy problem.
You can go through a riot.
/*by Silvern*/#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<vector>using namespacestd;Const intmxn= -;intRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intrans=1e9;intANS[MXN];intN,V[MXN],G,W[MXN][MXN];intNOW[MXN],CPY[MXN];BOOLCheck () {//for (int i=1;i<=n;i++) printf ("%d", Now[i]);//printf ("\ n"); for(intI=1; i<=n;i++) if(Now[i]<v[i])return 0; return 1;}voidDFS (intResintPOS) { if(Res>=rans)return; if(check ()) {rans=Res; memcpy (ans,cpy,sizeofans); return; }//printf ("%d%d\n", res,pos); for(inti=pos;i<=g;i++){ for(intj=1; j<=n;j++) now[j]+=W[i][j]; Cpy[res]=i; DFS (Res+1, i+1); for(intj=1; j<=n;j++) now[j]-=W[i][j]; } return;}intMain () {n=read (); inti,j; for(i=1; i<=n;i++) v[i]=read (); G=read (); for(i=1; i<=g;i++) for(j=1; j<=n;j++) W[i][j]=read (); DFS (1,1); printf ("%d", rans-1); for(i=1; i<rans;i++) printf ("%d", Ans[i]); return 0;}
Rokua P1460 Healthy Holstein cow Healthy Holsteins