usaco Healthy Holsteins
来源:互联网 发布:奥尼尔新秀赛季数据 编辑:程序博客网 时间:2024/05/19 23:00
奶牛需要v种一定量的维他命。
给你g种食物和他们维他命含量,求出最少需要哪几种食物,即可满足要求。每种食物只能喂一次。
这题可以直接搜索:
对于每种食物,有两种选择,选它或者不选。依靠这两种判断就可以简单搜索了。
/**TASK: holsteinID: DickensToneLANG: C++**/#include<iostream>#include<cstdio>using namespace std;const int inf = 100000000;int v, g;int need[30];int feed[20][30];int ans[20];int now[30];int vnow[30];int cnt;bool check(){ for(int i = 0; i < v; i++) { if(now[i] < need[i]) return false; } return true;}void dfs(int deep, int num){ if(deep == g) return; for(int i = 0; i < v; i++) { now[i] += feed[deep][i]; } vnow[num] = deep; if(check()) { //printf("%d\n", num); if(num < cnt) { cnt = num; for(int i = 1; i <= cnt; i++) ans[i] = vnow[i]; } } else dfs(deep + 1, num + 1); for(int i = 0; i < v; i++) now[i] -= feed[deep][i]; dfs(deep + 1, num);}int main(){ freopen("holstein.in", "r", stdin); freopen("holstein.out", "w", stdout); while(scanf("%d", &v) == 1) { cnt = inf; for(int i = 0; i < v; i++) { scanf("%d", &need[i]); } scanf("%d", &g); for(int i = 0; i < g; i++) for(int j = 0; j < v; j++) scanf("%d", &feed[i][j]); dfs(0, 1); printf("%d ", cnt); for(int i = 1; i < cnt; i++) printf("%d ", ans[i] + 1); printf("%d\n", ans[cnt] + 1); } return 0;}
阅读全文
0 0
- 【搜索】【USACO】Healthy Holsteins
- usaco training-Healthy Holsteins
- USACO Healthy Holsteins
- usaco Healthy Holsteins
- [USACO]Healthy Holsteins
- USACO:Healthy Holsteins
- USACO-Healthy Holsteins
- USACO Healthy Holsteins
- USACO 2.1 Healthy Holsteins
- USACO 2.1-Healthy Holsteins
- USACO 2.1 Healthy Holsteins
- usaco Healthy Holsteins
- USACO Healthy Holsteins
- usaco Healthy Holsteins
- USACO :Healthy Holsteins 解题报告
- USACO 2.1.5 Healthy Holsteins
- USACO 2.1.4Healthy Holsteins
- [USACO 2.1.4] Healthy Holsteins
- JavaScript-day19-个人学习笔记
- 外观模式
- ABAQUS更改默认工作目录
- 机房收费系统——可行性研究报告
- 多台电脑磁盘(文件共享 磁盘共享)局域网共享
- usaco Healthy Holsteins
- hdu 2609 How many
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776F. Sherlock's bet to Moriarty(待翻译)
- 基于GSoap/protobuf的服务性能优化
- XML头声明和standalone的解释
- iOS开发代码规范
- 编译?
- java类加载
- c++日志输出