USACO Healthy Holsteins
来源:互联网 发布:windows系统模拟器 编辑:程序博客网 时间:2024/05/19 23:59
首先看题目:
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 vitaminsLine 2:V integers (1 <= each one <= 1000), the minimum requirement for each of the V vitamins that a cow requires each dayLine 3:integer G (1 <= G <= 15), the number of types of feeds availableLines 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)
4100 200 300 400350 50 50 50200 300 200 300900 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: njuwz151TASK: holsteinLANG: C++*/#include <iostream>#include <cstdio>#include <bitset>#include <cstring>using namespace std;const int max_v = 30;const int max_g = 20;int main() { freopen("holstein.in", "r", stdin); freopen("holstein.out", "w", stdout); bitset<max_g> minbit(0); int min_count = max_g + 1; int feed[max_v]; int v; int req[max_v]; cin >> v; for(int i = 0; i < v; i++) { cin >> req[i]; } int g; int food[max_g][max_v]; cin >> g; for(int i = 0; i < g; i++) { for(int j = 0; j < v; j++) { cin >> food[i][j]; } } for(int i = 0; i < (1 << g); i++) { bitset<max_g> bit(i); int to_feed[max_v]; memset(to_feed, 0, sizeof to_feed); for(int j = 0; j < g; j++) { if(bit[j]) { for(int k = 0; k < v; k++) { to_feed[k] += food[j][k]; } } } bool valid = true; for(int j = 0; j < v; j++) { if(to_feed[j] < req[j]) { valid = false; break; } } if(valid && int(bit.count()) < min_count) { minbit = bit; min_count = minbit.count(); continue; } if(valid && int(bit.count()) == min_count) { bool ok = true; for(int i = 0; i < g; i++) { if(bit[i] > minbit[i]) { break; } else if(bit[i] < minbit[i]) { ok = false; break; } } if(ok) { minbit = bit; min_count = minbit.count(); } } } cout << min_count; for(int i = 0; i < g; i++) { if(minbit[i]) { cout << " " << i+1; } } cout << endl;}
- 【搜索】【USACO】Healthy Holsteins
- usaco training-Healthy Holsteins
- USACO Healthy Holsteins
- usaco Healthy Holsteins
- [USACO]Healthy Holsteins
- USACO:Healthy Holsteins
- USACO-Healthy Holsteins
- USACO Healthy Holsteins
- USACO 2.1 Healthy Holsteins
- USACO 2.1-Healthy Holsteins
- USACO 2.1 Healthy Holsteins
- usaco Healthy Holsteins
- USACO Healthy Holsteins
- usaco Healthy Holsteins
- USACO :Healthy Holsteins 解题报告
- USACO 2.1.5 Healthy Holsteins
- USACO 2.1.4Healthy Holsteins
- [USACO 2.1.4] Healthy Holsteins
- vue组件中数据的传递
- USACO Sorting a Three-Valued Sequence
- U8SDK打包出现Duplicate file错误导致打包失败的解决方法
- html中canvas遇到的问题
- iOS-如何消除警告
- USACO Healthy Holsteins
- SASS学习
- 利用 Hadoop FileSystem listStatus 遍历文件目录 实现HDFS操作
- USACO hamming
- 聚合工程maven报错:Could not resolve dependencies for project
- 关于数据库中除法的一个小问题
- 培养属立足于未来的产品经理人1
- USACO Dynamic Programming (1)
- Codeforces 818B Permutation Game