列举所有的子集找最优就行。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
int v[SZ],arr[SZ][SZ]; inline int lowbit(int x)
{
return x&-x;
} int getdgt(int x)
{
int res=;
for(;x;x-=lowbit(x),++res);
return res;
} bool chk(int x,int n)
{
int tmp[SZ];
memset(tmp,,sizeof(tmp));
for(int i=;i<;++i)
{
if(x&(<<i))
{
for(int j=;j<n;++j)
{
tmp[j]+=arr[i][j];
}
}
}
for(int j=;j<n;++j)
{
if(tmp[j]<v[j])return ;
}
return ;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n;
cin>>n;
for(int i=;i<n;++i)cin>>v[i];
int m;
cin>>m;
for(int i=;i<m;++i)
{
for(int j=;j<n;++j)
{
cin>>arr[i][j];
}
}
int mind=INF,res=;
for(int i=;i<(<<m);++i)
{
if(getdgt(i)<mind&&chk(i,n))
{
mind=getdgt(i);
res=i;
}
}
cout<<mind;
for(int i=;i<;++i)
{
if(res&(<<i))cout<<" "<<i+;
}
cout<<endl;
}
return ;
}

p1460 Healthy Holsteins的更多相关文章

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

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

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

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

  3. USACO Healthy Holsteins

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

  4. USACO 2.1 Healthy Holsteins

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

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

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

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

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

  7. 【USACO 2.1】Healthy Holsteins

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

  8. USACO Healthy Holsteins DFS

    使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...

  9. USACO Section 2.1 Healthy Holsteins

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

随机推荐

  1. 网络存储结构简明分析—DAS、NAS和SAN 三者区别

    存储的总体分类     主流存储结构   网络存储结构大致分为三种:直连式存储(DAS:Direct Attached Storage).存储区域网络(SAN:Storage Area Network ...

  2. Web 页面性能分析笔记

    网页慢的原因不一定只是前端,所以需要结合Network一起看 如何评价一个页面打开得快不快,可以用两个指标描述,一个是ready的时间,另一个是load的时间. 如下示例表示,read时间是2.72s ...

  3. Python 必备好库 - 好工具收藏

    apscheduler collections collections.OrderDict collections.defaultdict Python 标准库提供了 collections 模块.这 ...

  4. openwrt编译e2fsprogs-1.43时报错misc/create_inode.c:399:18: error: conflicting types for 'copy_file_range'

    1. 详细报错信息 misc/create_inode.c:399:18: error: conflicting types for 'copy_file_range' static errcode_ ...

  5. npm的安装和使用?

    参考: http://www.cnblogs.com/chyingp/p/npm.html 在css中使用变量, 采用less或sass来编译css 改变网页网站开发和构建的方式, 除了用emmet( ...

  6. p2596 书架(Treap)

    写平衡树修锅快修到死系列 我太蠢了 其实是平衡树裸体裸题 插入,删除,交换前驱或后继,查询rank和kth 维护一个pos数组,表示第i个书的编号 然后注意许许多多的细节,没了 #include &l ...

  7. Vue属性中带’-‘的处理方式

    我们在写属性时经常会加入’-‘来进行分词,比如:<panda from-here=”China”></panda>,那这时我们在props里如果写成props:[‘form-h ...

  8. 洛谷P2782 友好城市 DP

    やはり まだあしたということは嘘でしょう.ぜんぶ忘れた( ´・ヮ・`) 所以今天就贴一道水题吧 原题>>https://www.luogu.org/problem/show?pid=278 ...

  9. UVa 11624 Fire!(着火了!)

    UVa 11624 - Fire!(着火了!) Time limit: 1.000 seconds Description - 题目描述 Joe works in a maze. Unfortunat ...

  10. 极简 R 包建立方法--转载

    https://cosx.org/2013/11/building-r-packages-easily/ 最近想试一下捣腾一个 R 包出来,故参考了一些教程.现在看到的最好的就是谢益辉大大之前写过的开 ...