使用排列组合,遍历所有可能的情况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的更多相关文章

  1. USACO Healthy Holsteins

    首先看题目: Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dair ...

  2. USACO 2.1 Healthy Holsteins

    Healthy HolsteinsBurch & Kolstad Farmer John prides himself on having the healthiest dairy cows ...

  3. 洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins

    P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...

  4. P1460 健康的荷斯坦奶牛 Healthy Holsteins

    P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...

  5. P1460 健康的荷斯坦奶牛 Healthy Holsteins (简单的dfs)

    题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少. 给出牛所需的最低的维他命 ...

  6. 【USACO 2.1】Healthy Holsteins

    /* TASK: holstein LANG: C++ URL: http://train.usaco.org/usacoprob2?a=SgkbOSkonr2&S=holstein SOLV ...

  7. USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】

    holstein解题报告 --------------------------------------------------------------------------------------- ...

  8. USACO1.6 Healthy Holsteins【dfs/bfs 爆搜】

    题目传送门 饲料种数只有15 枚举每种选或不选一共也就只有$2^{15}=32768$ 爆搜可过觉得bfs要快一些? 但是dfs更方便处理字典序 只需要顺序遍历并且先搞选它的情况就可以了 而且在这种规 ...

  9. USACO Section 2.1 Healthy Holsteins

    /* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #incl ...

随机推荐

  1. [LeetCode]题解(python):097-Interleaving String

    题目来源: https://leetcode.com/problems/interleaving-string/ 题意分析: 给定字符串s1,s2,s3,判断s3是否由s1和s2穿插组成.如“abc” ...

  2. 隐藏nginx 版本号信息(转)

    为了安全,想将http请求响应头里的nginx版本号信息隐藏掉: 1. nginx配置文件里增加 server_tokens off; server_tokens作用域是http server loc ...

  3. C++头文件的包含顺序研究

    一.<Google C++ 编程风格指南>里的观点 公司在推行编码规范,领导提议基本上使用<Google C++ 编程风格指南>.其中<Google C++ 编程风格指南 ...

  4. C++_template_栈的链式存储及实现

    由于在C++数据结构中的代码不完整,特补全.等日后当工程库调用. 若有疑问,请留言. #include<iostream> using namespace std; template< ...

  5. HDU 1501 Zipper 动态规划经典

    Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  6. ASP.NET上传文件的三种基本方法

    ASP.NET依托.net framework类库,封装了大量的功能,使得上传文件非常简单,主要有以下三种基本方法. 方法一:用Web控件FileUpload,上传到网站根目录. Test.aspx关 ...

  7. 解决了clang: error: linker command failed with exit code 1 (use -v to see invocation) 解决方法

    1.”Build Settings”->”Enable Bitcode”设置为NO 2.TARGETS -->  Build Settings --> Architectures - ...

  8. 简单字符串模式匹配算法的C++实现

    /* * simpleIndex.cpp * Author: Qiang Xiao * Time: 2015-07-13 */ #include<iostream> #include< ...

  9. Oracle语句优化规则(一)

    1. 选用适合的ORACLE优化器     ORACLE的优化器共有3种:    a. RULE (基于规则)   b. COST (基于成本) c. CHOOSE (选择性)     设置缺省的优化 ...

  10. web.xml 的加载顺序

    context-param -> listener -> filter -> servlet