#P1460. [USACO2.1] Healthy Holsteins

    ID: 5573 远端评测题 1000ms 125MiB 尝试: 13 已通过: 5 难度: 3 上传者: 标签>搜索USACO广度优先搜索 BFS深度优先搜索 DFS

[USACO2.1] 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 his cows. Help Farmer John feed the 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.

输入格式

  • Line 1: Integer VV (1V251 \le V \le 25), the number of types of vitamins.
  • Line 2: VV integers (11 \le each one 1000\le 1000), the minimum requirement for each of the VV vitamins that a cow requires each day.
  • Line 3: Integer GG (1G151 \le G \le 15), the number of types of feeds available.
  • Lines 4..G+3G+3: VV integers (00 \le each one 1000\le 1000), the amount of each vitamin that one scoop of this feed contains. The first line of these GG lines describes feed 11; the second line describes feed 22; and so on.

输出格式

The output is a single line 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 feed types yields a minimum number of scoops, choose the set with the smallest feed type numbers.

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

提示

USACO Training Section 2.1.