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以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
随机推荐
- 基于express+mongodb+pug的博客系统——pug篇
很久之前就想自己搭一个博客了,最开始用hexo+github,但是换电脑后总是有些麻烦.后来使用WordPress,但是用WordPress总觉得没什么技术含量,前后端都是人家写好的,而且买的垃圾虚拟 ...
- C#基础知识-编程思想之封装(七)
既然是学习面向对象的编程那自然要了解面向对象中的三大基石,封装.继承和多态. 我觉得要解释这三大基本概念用一篇文档很难解释清楚,想要具体形象的去了解,还是需要每一个概念用一个篇幅来说明,将封装.继承和 ...
- 用Go造轮子-管理集群中的配置文件
写在前面 最近一年来,我都在做公司的RTB广告系统,包括SSP曝光服务,ADX服务和DSP系统.因为是第一次在公司用Go语言实现这么一个大的系统,中间因为各种原因造了很多轮子.现在稍微有点时间,觉着有 ...
- LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2
LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2 你是否遇见过:安装LNMP1.3环境后,运行ThinkPHP 3.2,只能打开首页,不能访问控制器,报404错误. 按照 ...
- Spring切面编程步骤
什么是面向切面编程 面向对象的编程主要注重核心业务,而面向切面编程主要关注一些不是核心的业务,但又是必须的辅助功能,比如一个完整的系统中,记录平时系统运行时抛出的异常,需要我们去记录,以便我们对系统尽 ...
- ArrayList源码解析(二)自动扩容机制与add操作
本篇主要分析ArrayList的自动扩容机制,add和remove的相关方法. 作为一个list,add和remove操作自然是必须的. 前面说过,ArrayList底层是使用Object数组实现的. ...
- RPi WiringPi安装使用
sudo apt-get install git-core git clone git://git.drogon.net/wiringPi cd wiringPi ./build 使用Exam ...
- Qt Opencv 在Linux下摄像头简单示例(转)
下面写的文章也许网上也有类似的,但是大多数都没有给出思路及背景,让初学者每次都只能学到一点皮毛,不少知识需要大量搜索零碎地拼凑起来.题外话,虽然现在是碎片化信息时代,但正是这样信息整合能力也显得非常重 ...
- Vue之Vuex
一.什么是vuex Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.简单来说就是一个数据统一 ...
- Mac和Windows系统下Mysql数据库的导入导出
最近在构建数据库的过程中,需要将Mac os系统下的Mysql数据库导出成.sql文件,然后导入到windows系统下的Mysql中.经过学习总结出的步骤如下: 一.Mac os导出Mysql数据库 ...