USACO Healthy Holsteins DFS
使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合
数据规模不大,暴力过去最多也就是2^15 = 23768种情况
所以就暴力咯,不过还是Debug了一会
Source Code:
/*
ID: wushuai2
PROG: holstein
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; int vv[], aa[][];
int ans[], a[], cur[];
int v, g; void dfs(int n, int w, int a[]){ int i, j;
memset(cur, , sizeof(cur));
for(i = ; i <= a[]; ++i){
for(int j = ; j < v; ++j){
cur[j] += aa[a[i]][j];
}
}
for(i = ; i < v; ++i){
if(cur[i] < vv[i]) break;
}
if(i == v){
if(w < ans[]){
/*
for(int i = 1; i <= a[0]; ++i){
cout << a[i] + 1 << ' ';
}
cout << endl;
*/
for(i = ; i <= a[]; ++i){
ans[i] = a[i];
}
return;
}
}
for(int i = n + ; i < g; ++i){
++a[];
a[a[]] = i;
dfs(i, w + , a);
--a[];
}
} int main() {
ofstream fout ("holstein.out");
ifstream fin ("holstein.in");
int i, j, k, t, n, s, c, w, q; fin >> v;
for(i = ; i < v; ++i){
fin >> vv[i];
}
fin >> g;
for(i = ; i < g; ++i){
for(j = ; j < v; ++j){
fin >> aa[i][j];
}
}
ans[] = INF;
for(i = ; i < g; ++i){
a[] = ;
a[] = i;
dfs(i, , a);
}
fout << ans[];
for(i = ; i <= ans[]; ++i){
fout << ' ' << ans[i] + ;
}
fout << endl; fin.close();
fout.close();
return ;
}
USACO Healthy Holsteins DFS的更多相关文章
- USACO Healthy Holsteins
首先看题目: Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dair ...
- 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以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins (简单的dfs)
题目描述 农民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解题报告 --------------------------------------------------------------------------------------- ...
- USACO1.6 Healthy Holsteins【dfs/bfs 爆搜】
题目传送门 饲料种数只有15 枚举每种选或不选一共也就只有$2^{15}=32768$ 爆搜可过觉得bfs要快一些? 但是dfs更方便处理字典序 只需要顺序遍历并且先搞选它的情况就可以了 而且在这种规 ...
- USACO Section 2.1 Healthy Holsteins
/* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #incl ...
随机推荐
- 二、Python-----用户交互
1.用户交互 Python 3.0的写法 name = input("Please input your name:") Python 2.0的写法 name = raw_inpu ...
- [转]swift 学习资源 大集合
今天看到了一个swift的学习网站,里面收集了很多学习资源 [转自http://blog.csdn.net/sqc3375177/article/details/29206779] Swift 介绍 ...
- IOS 表视图(UITableVIew)的使用方法(7)表视图的编辑功能(拖拉调整排序位置)
除了每个单元行左边的删除和新增图标,UITableView还支持在单元行的右侧显示一个供用户拖拉调整排序位置的控件. 不过如果要显示此控件,UITableView的数据源需要实现以下的方法. -(vo ...
- mybatis+postgresql平台
mybatis+postgresql平台 最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮 ...
- Protel99se教程三:新建PCB文件以及PCB基本设定
在上一课,我们绘制好SCH原理图后,在这一节课开始,我们介绍,如何将SCH转化成PCB文件,在这一节课,我们主要给大家讲解,如果新建PCB文件以及载入封装图. 第一步:在Documents目录下,新建 ...
- Microsoft Deployment Toolkit 2013 Preview Release Now Available
MDT 2013 provides a common console with comprehensive tools and guidance for every organizational ro ...
- 设计模式 - 适配器模式(adapter pattern) 具体解释
适配器模式(adapter pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 适配器模式(adapter pattern): 将一个类的接 ...
- OS之多线程
os中引入进程的目的是,为了描述和实现多个程序的并发执行,以改善资源利用率及提高系统的吞吐量. 为什么要引入线程?这是为了减少程序并发执行时系统所付出的额外开销(堆栈切换的开销等),使os具有更好的并 ...
- nodejs hello world (调用文件执行没反应)
今天学习了node.js ,来看一下hello world 的写法. 1. 首先安装node.js的驱动文件.http://nodejs.org/ 2. a:安装好node之后,在CMD窗口输入nod ...
- [置顶] 浅谈大型web系统架构
转载原文:http://blog.csdn.net/dinglang_2009/article/details/6863697 分类: 大规模Web 2.0架构 2011-10-11 18:27 12 ...