p1460 Healthy Holsteins
列举所有的子集找最优就行。
#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的更多相关文章
- 洛谷 P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- 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
题目描述 农民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 Healthy Holsteins DFS
使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...
- USACO Section 2.1 Healthy Holsteins
/* ID: lucien23 PROG: holstein LANG: C++ */ #include <iostream> #include <fstream> #incl ...
随机推荐
- git给log设置别名来快速查看友好的log信息
把lg配置成了:git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(y ...
- thinkphp如何省略index.php
省略index.php叫做 伪静态化; 共有四个步骤: MariaDB[(none)]: 表示, 目前没有选择/使用 任何数据库. 如果use了数据库, 会提示: MariaDB[mysql]... ...
- hihoCoder week14 无间道之并查集
并查集的基本使用 #include <bits/stdc++.h> using namespace std; ; int n, fa[N]; int cnt, tot; map<st ...
- Even Odds (java)
从1到n的奇数,从1到n之间的偶数,排列在一起,找到第k个数 Input 输入包含 n and k (1 ≤ k ≤ n ≤ 1012). Please, do not use the %lld sp ...
- Vue内置的Component标签用于动态切换组件
html <div id="app"> <component :is="cut"></component> <butt ...
- 给大家分享两套WordPress收费主题
主题一:No.7 – 极简 by 大当家 1.主题网址:http://qzhai.net/2016-03-546.html 2.主题预览:http://qzhai.net/000/?theme=No. ...
- spring与mybatis四种整合方法
转载: 1.采用数据映射器(MapperFactoryBean)的方式,不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数. (1)Spring配置文件: <!-- 引 ...
- windows下远程连接Mysql
使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口. 使用“mysql -uroot -proot”命令可以连接到本地的mysql服务. 使用“use mysql” ...
- C#端加载数据库,Combobox与Node控件绑定数据源demo示例
最近一直在做网页.用的js比较多,最近需要做一个C#相关的demo,一开始还有点不适应,写了几句有点感觉了 本篇博客的主要内容是C#怎么读取数据库文件里的数据以及相关控件如何绑定数据源,所做的Demo ...
- spring boot Tomcat访问日志
1.Tomcat设置访问日志 <Host name="localhost" appBase="webapps" unpackWARs="true ...