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以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...
随机推荐
- Java线程安全 关于原子性与volatile的试验
1. 变量递增试验 static /*volatile*/ int shared=0;//volatile也无法保证++操作的原子性 static synchronized int incrShare ...
- dubbo+zookeeper+springmvc+mybatis+shiro+redis架构
内容管理(CMS)系统,包括内容管理,栏目管理.站点管理.公共留言.文件管理.前端网站展示等功能: 在线办公(OA)系统,主要提供简单的流程实例. Jeesz提供了常用工具进行封装,包括日志工具.缓存 ...
- 基于OWIN+DotNetOpenOAuth实现OAuth2.0
这几天时间一直在研究怎么实现自己的OAuth2服务器,对于太了解OAuth原理以及想自己从零开始实现的,我建议可以参考<Apress.Pro ASP.NET Web API Security&g ...
- 网站权限管理 之 角(jue)色管理
公司或网站的正常运行,离不开管理员对各个员工的合理分配,那先看看权限管理中的角色管理好了: 要更改用户的角色,那么先来理一下思路: (1)用户现在是什么角色? (2)用户将要成为什么角色? (3)怎样 ...
- 4.Java 加解密技术系列之 HMAC
Java 加解密技术系列之 HMAC 序 背景 正文 代码 结束语 序 上一篇文章中简单的介绍了第二种单向加密算法 — —SHA,同时也给出了 SHA-1 的 Java 代码.有这方面需求的童鞋可以去 ...
- 开涛spring3(6.8) - AOP 之 6.8 切面实例化模型
所谓切面实例化模型指何时实例化切面. Spring AOP支持AspectJ的singleton.perthis.pertarget实例化模型(目前不支持percflow.percflowbelow ...
- R语言与分类算法的绩效评估(转)
关于分类算法我们之前也讨论过了KNN.决策树.naivebayes.SVM.ANN.logistic回归.关于这么多的分类算法,我们自然需要考虑谁的表现更加的优秀. 既然要对分类算法进行评价,那么我们 ...
- Coursera 机器学习笔记(二)
主要为第三周课程内容:逻辑回归与正则化 逻辑回归(Logistic Regression) 一.逻辑回归模型引入 分类问题是指尝试预测的是结果是否属于某一个类. 维基百科的定义为:根据已知训练区提供的 ...
- CSS3学习系列之选择器(二)
first-child选择器和last-child选择器 first-child指定第一个元素.last-child指定最后一个子元素. 例如: <!DOCTYPE html> <h ...
- 织梦DEDECMS中的默认文件夹的名称怎么修改呢?
1.首先找到系统配置文件,一般此文件会存放在Include目录下,文件名称为:common.inc.php. 2.打开common.inc.php,以修改模板目录templets为例, ...