USACO 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: njuwz151
- TASK: holstein
- LANG: C++
- */
- #include <iostream>
- #include <cstdio>
- #include <bitset>
- #include <cstring>
- using namespace std;
- const int max_v = ;
- const int max_g = ;
- int main() {
- freopen("holstein.in", "r", stdin);
- freopen("holstein.out", "w", stdout);
- bitset<max_g> minbit();
- int min_count = max_g + ;
- int feed[max_v];
- int v;
- int req[max_v];
- cin >> v;
- for(int i = ; i < v; i++) {
- cin >> req[i];
- }
- int g;
- int food[max_g][max_v];
- cin >> g;
- for(int i = ; i < g; i++) {
- for(int j = ; j < v; j++) {
- cin >> food[i][j];
- }
- }
- for(int i = ; i < ( << g); i++) {
- bitset<max_g> bit(i);
- int to_feed[max_v];
- memset(to_feed, , sizeof to_feed);
- for(int j = ; j < g; j++) {
- if(bit[j]) {
- for(int k = ; k < v; k++) {
- to_feed[k] += food[j][k];
- }
- }
- }
- bool valid = true;
- for(int j = ; 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 = ; 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 = ; i < g; i++) {
- if(minbit[i]) {
- cout << " " << i+;
- }
- }
- cout << endl;
- }
USACO Healthy Holsteins的更多相关文章
- USACO Healthy Holsteins DFS
使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...
- USACO 2.1 Healthy Holsteins
Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dairy cows ...
- 洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- 【USACO 2.1】Healthy Holsteins
/* TASK: holstein LANG: C++ URL: http://train.usaco.org/usacoprob2?a=SgkbOSkonr2&S=holstein SOLV ...
- USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】
holstein解题报告 --------------------------------------------------------------------------------------- ...
- USACO Section 2.1 Healthy Holsteins
/* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #incl ...
- 洛谷P1460 健康的荷斯坦奶牛 Healthy Holsteins
题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins (简单的dfs)
题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
随机推荐
- How to change current process to background process
Situation: there is a script or command is running, but we need to close current box/windows to do o ...
- 为什么字符串会有length属性-JS中包装对象
任何原始类型的数据 (primitive type) 比如 String类型的字符串 "abcd" "abcd" 是原始类型的数据 但是 当他调用 le ...
- Aspose.Cells.dll操作execl
附件:Aspose.Cells.dll 1.创建execl(不需要服务器或者客户端安装office) public void DCExexl(DataTable dt) { Workbook wb ...
- C# MVC权限验证
前言 之前一直没怎么接触过权限验证这块,刚好公司老平台改版,就有了这篇权限验证.此篇文章大致讲解下 精确到按钮级别的验证如何实现.以及权限验证设计的参考思路(菜鸟一枚,大神勿喷). 在开发大项目的时候 ...
- 项目管理之 Objective-C 编码规范
目录: 一.格式化代码 二.命名 命名要求 1. 类的命名: 规则: 大驼峰命名法,每个单词的首字母都采用大写字母.一般添加业务前缀.后缀一般是当前类的种类. ViewController:后缀:Vi ...
- [oracle]Oracle数据库安全管理
目录 + 1.数据库安全控制策略概述 + 2.用户管理 + 3.资源限制与口令管理 + 4.权限管理 + 5.角色管理 + 6.审计 1.数据库安全控制策略概述 安全性是评估一个数据库的重 ...
- React模块化开发
借助前端构建工具webpack 1.webpack是facebook为react量身打造的构建工具 2.主要作用是实现模块化,代码整合,代码分割的作用 3.使用webpack整合以后 也不需要使用br ...
- python中xrange用法分析
本文实例讲述了python中xrange用法.分享给大家供大家参考.具体如下: 先来看如下示例: >>> x=xrange(0,8) >>> print x xra ...
- 使用Mingw编译wxSqlite3-3.0.5
最近在学习wxWidgets,而且官方也出了3.0版本,貌似还不错的样子,准备做个小程序来练手.中间需要用到数据库看到很多人推荐wxSqlite3就去下来看看,以下是我使用TDM-GCC 4.8.1( ...
- iOS 手势
一.看这里 二.抽象类 UIGestureRecognizer 继承于该类的有7类:轻点,捏合,拖拽,滑动,长按,旋转,边缘滑动; 一个手势可以绑定多个事件 - (void)addTarget:( ...