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: des_jas1
PROG: holstein
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
//#define fin cin
//#define fout cout
using namespace std;

const int mmax=16,maxx=26;
int P=mmax,V=0,G=0,ans[mmax],tans[mmax],vm[maxx],scoop[mmax][maxx],cv[maxx]={0};

void dfs(int k,int idx)
{
	k++;
	if(k>=P)
		return;
	int i,j,flag;
	for(i=idx+1;i<=G;++i)
	{
		flag=0;
		for(j=1;j<=V;++j)
		{
			cv[j]+=scoop[i][j];
			if(cv[j]<vm[j]) //放在这里判断比较合适
				flag=1;
		}
		tans[k]=i;
		if(!flag)
		{
			P=k;
		    for(j=1;j<=P;j++)
			    ans[j]=tans[j];
			for(j=1;j<=V;++j)
			    cv[j]-=scoop[i][j];  //漏掉这个错很惨
			return;
		}
		dfs(k,i);
		for(j=1;j<=V;++j)
			cv[j]-=scoop[i][j];
	}
	return;
}


int main() 
{
	ofstream fout("holstein.out");
    ifstream fin("holstein.in");
	fin>>V;
	int i,j;
	for(i=1;i<=V;++i)
		fin>>vm[i];
	fin>>G;
	for(i=1;i<=G;++i)
		for(j=1;j<=V;++j)
			fin>>scoop[i][j];
	dfs(0,0);
	fout<<P;
	for(i=1;i<=P;++i)
		fout<<" "<<ans[i];
	fout<<endl;
	fout.close();
	fin.close();
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为一个程序员,也许你拥有高超的专业技能,写出各种高深、优雅的代码,以各种技术对付程序的BUG,面对机器,你就是掌控一切的神。但程序员却无法对抗由于职业本身带来的各种身体问题,比较背疼,头疼,颈椎病,高血压,肥胖,等等。。。身体健康一直是程序员心中的通。本书以众多程序员为对象,提供一些足以应对各种身体问题建议,包括生活习惯,小建议,营养饮食等方面。非常实用,可行。亚马逊5星图书。 下面是目录: Foreword . . . . . . . . . . . . . . xi Acknowledgments . . . . . . . . . . . xiii Preface . . . . . . . . . . . . . . xv 1. Making Changes . . . . . . . . . . . . 1 Unit-Testing Your Health 2 1.1 1.2 The Mind-Body Connection 3 1.3 An Iterative Approach to Health 4 1.4 The Science Behind Habits 7 1.5 Reprogramming Your Habits 10 1.6 Retrospective 12 2. Bootstrapping Your Health . . . . . . . . . 13 Thinking on Your Feet 14 2.1 2.2 Walking Your Way to Better Health 17 2.3 The Time of Your Life 20 2.4 Learning How to Walk 22 2.5 Getting Out the Door 24 2.6 Retrospective 25 3. A Farewell to Chairs? . . . . . . . . . . 29 Sitting Is Considered Harmful 30 3.1 3.2 Standing Up for the Truth 34 3.3 Enhancing Your Workstation 38 3.4 Retrospective 43 4. Agile Dieting . . . . . . . . . . . . 47 An Iterative Approach to Dieting 48 4.1 4.2 Balanced Nutrition Over Idiosyncratic Diets 50 4.3 Eating Your Brains Out 52 4.4 Counting Calories Over Following Trends 55 4.5 Adjusting Your Caloric Intake 57 4.6 Individual Tastes Over Predefined Menus 59 4.7 Retrospective 61 5. Preventing Headaches and Eye Strain . . . . . . 65 Unit-Testing Your Vision 66 5.1 5.2 Avoiding Computer Vision Syndrome 69 5.3 Avoiding Headache Triggers 71 5.4 Treating Headache Symptoms 74 5.5 Retrospective 76 6. Preventing Back Pain . . . . . . . . . . 79 Unit-Testing Your Core Muscles 80 6.1 6.2 Understanding the Anatomy of the Back 86 6.3 Strengthening Your Powerhouse 88 6.4 Developing Better Ergonomics 96 6.5 Retrospective 99 7. Preventing Wrist Pain . . . . . . . . . . 103 Unit-Testing Your Wrists 104 7.1 7.2 Understanding the Causes of Wrist Pain 108 7.3 Using Exercise to Prevent Pain 108 7.4 Reducing Tension with the Alexander Technique 113 7.5 Restricting Movement with Braces 116 7.6 Retrospective 118 8. Making Exercise Pragmatic . . . . . . . . . 121 Exercising Your Brain 122 8.1 8.2 Taking Healthy Pomodoro Breaks 122 8.3 Keeping a Log 126 8.4 Playing Games with Your Health 127 8.5 Taking Your Fitness to the Web 131 8.6 Retrospective 132 9. Thinking Outside the Cube . . . . . . . . . 135 Dosing on Vitamin D 136 9.1 9.2 Shedding Light on the Vitamin D Hype 137 9.3 Boosting Your Immune System 139 9.4 Dealing with the Common Cold 141 9.5 Thinking Under the Trees 142 9.6 Retrospective 144 Contents • viii 10. Refactoring Your Fitness . . . . . . . . . 147 Warming Up 148 10.1 10.2 Understanding the Dimensions of Fitness 150 10.3 Unit-Testing Your Fitness 151 10.4 Upgrading Your Hardware 159 10.5 Retrospective 169 11. Teaming Up . . . . . . . . . . . . 173 Message-Passing 174 11.1 11.2 Investing in Your Health 175 11.3 Playing Well with Others 178 11.4 Building a Better Team 182 11.5 Retrospective 183 12. Onward, Healthy Programmer . . . . . . . . 187 12.1 Continuous Improvement 188 12.2 Creating Social Habits 190 12.3 The Joy of Being Healthy 191 A1. Goals . . . . . . . . . . . . . . 193 A2. Examples . . . . . . . . . . . . . 195 A2.1 Examples of Fruit/Vegetable Servings 195 A2.2 Example Day 196 A3. Further Reading . . . . . . . . . . . 197 A3.1 Books 197 A3.2 Publications 197 A4. Bibliography . . . . . . . . . . . . 201 Index . . . . . . .

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值