• 2.1.4 Healthy Holsteins


    Healthy Holsteins
    Burch & Kolstad

    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.

    PROGRAM NAME: holstein

    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: makeeca1
    PROG: holstein
    LANG: PASCAL
    }
    const maxn=1000;
    var v,g,i,j,x,p,pos,min:longint;f:boolean;
        rec,a,b,need:array[1..maxn]of longint;
        num:array[1..maxn,1..maxn]of longint;
    
    begin
      assign(input,'holstein.in');reset(input);
      assign(output,'holstein.out');rewrite(output);
      readln(v);
      for i:=1 to v do read(need[i]);readln;
      readln(g);
      for i:=1 to g do
      begin
        for j:=1 to v do read(num[i,j]);
        readln;
      end;          close(input);
      pos:=1<<g-1;
      fillchar(rec,sizeof(rec),0);min:=maxlongint;
      for p:=1 to pos do
      begin
        fillchar(a,sizeof(a),0);
        fillchar(b,sizeof(b),0);
        x:=0;
        for i:=1 to g do
        if (1<< (i-1))and p=1<< (i-1) then
        begin
          for j:=1 to v do inc(a[j],num[i,j]);
          inc(x);
          b[x]:=i;
        end;
        f:=true;
        for i:=1 to v do
        if a[i]<need[i]then f:=false;
        if f then
          if x<min then
          begin
            min:=x;
            fillchar(rec,sizeof(rec),0);
            for i:=1 to x do rec[i]:=b[i]
          end;
      end;
      write(min);
      for i:=1 to min do write(' ',rec[i]);writeln;
      close(output);
    end.
  • 相关阅读:
    二叉搜索树和双向链表 --剑指offer
    复杂链表的复制 --剑指offer
    二叉树中和为某一值的路径 --剑指offer
    二叉搜索树的后序遍历序列 --剑指offer
    从上往下打印二叉树 --剑指offer
    栈的压入、弹出序列 --剑指offer
    顺时针打印矩阵 --剑指offer
    树的子结构 --剑指offer
    JSON.toJSONString(joinPoint.getArgs())报错getOutputStream() has already been called for this response
    常用linux命令
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274554.html
Copyright © 2020-2023  润新知