Rokua P1460 Healthy Holstein cow Healthy Holsteins

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.