USACO holstein AC code
/*
ID:kevin_s1
PROG:holstein
LANG:C++
*/ #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath> using namespace std; #define MAXV 26
#define MAXG 16
#define INF 327699 //gobal variable====
int V;
int requirement[MAXV];
int G;
int feed[MAXG][MAXV];
int result; int ans[MAXG];
int vit[MAXV];
int res[MAXG];
//================== //function==========
bool check(){
bool flag = true;
for(int i = 1; i <= V; i++){
if(vit[i] < requirement[i])
flag = false;
}
return flag;
} void DFS(int deep, int count){
if(deep == G + 1){
if(check() == false)
return;
if(count < result){
result = count;
for(int i = 1; i <= result; i++){
res[i] = ans[i];
}
}
return;
}
for(int i = 1; i <= V; i++){
vit[i] += feed[deep][i];
}
ans[count + 1] = deep;
DFS(deep + 1, count + 1);
for(int i = 1; i <= V; i++){
vit[i] -= feed[deep][i];
}
DFS(deep + 1, count);
return;
} //================== int main(){
freopen("holstein.in","r",stdin);
freopen("holstein.out","w",stdout);
cin>>V;
for(int i = 1; i <= V; i++){
cin>>requirement[i];
}
cin>>G;
for(int i = 1; i <= G; i++){
for(int j = 1; j <= V; j++){
cin>>feed[i][j];
}
}
memset(res, 0, sizeof(res));
memset(ans, 0, sizeof(ans));
memset(vit, 0, sizeof(vit));
result = INF;
DFS(1, 0);
cout<<result;
for(int i = 1; i <= result; i++){
cout<<" "<<res[i];
}
cout<<endl;
return 0;
}
USACO holstein AC code的更多相关文章
- 20ms Ac Code
Rectangle Aread C Code #include <stdio.h> int computeArea(int A,int B,int C,int D,int E,int F, ...
- 【USACO】AC自动机
Description 对,这就是裸的AC自动机. 要求:在规定时间内统计出模版字符串在文本中出现的次数. Input 第一行:模版字符串的个数N. 第2->N+1行:N个字符串.(每个模版字符 ...
- cjoj P1435 - 【模板题 USACO】AC自动机 && 洛谷 P3796 【模板】AC自动机(加强版)
又打了一遍AC自动稽. 海星. 好像是第一次打trie图,很久以前就听闻这个思想了.OrzYYB~ // It is made by XZZ #include<cstdio> #inclu ...
- BZOJ3940:[USACO]Censoring(AC自动机,栈)
Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...
- USACO holstein 超时代码
/* ID:kevin_s1 PROG:holstein LANG:C++ */第八组数据跪了.半天都不出结果 #include <iostream> #include <cstdi ...
- 杭电1004 ac code
#include <stdio.h> #include <string.h> #include <stdlib.h> #define STR_LEN 256 str ...
- USACO Cow Cars
洛谷 P2909 [USACO08OPEN]牛的车Cow Cars https://www.luogu.org/problemnew/show/P2909 JDOJ 2584: USACO 2008 ...
- USACO Making the Grade
洛谷 P2893 [USACO08FEB]修路Making the Grade https://www.luogu.org/problemnew/show/P2893 JDOJ 2566: USACO ...
- USACO Mooo Moo
洛谷 P2214 [USACO14MAR]哞哞哞Mooo Moo 洛谷传送门 JDOJ 2416: USACO 2014 Mar Silver 3.Mooo Moo JDOJ传送门 Descripti ...
随机推荐
- Java学习笔记——File类文件管理及IO读写、复制操作
File类的总结: 1.文件和文件夹的创建 2.文件的读取 3.文件的写入 4.文件的复制(字符流.字节流.处理流) 5.以图片地址下载图片 文件和文件夹 相关函数 (boolean) mkdir( ...
- Redhat Linux NFS配置
Linux下,All deviceis file,所有的设备都是文件.当我们需要把某些文件夹就或者文件共享给其他用户,就可以使用网络文件系统. 本文介绍Redhat Linux下的NFS配置. 在使用 ...
- Kyoto Cabinet 使用及原理
Kyoto Cabinet 基本规格书 如果你知道 Tokyo Cabinet ,那么就应该知道 Kyoto Cabinet,因为他们都是同一个作者(平林幹雄)开发出来的 Key-Value 数据库. ...
- 什么是Platform Services Controller
Platform Services Controller (PSC) is a component of the VMware Cloud Infrastructure Suite. PSC deal ...
- C语言头文件的使用(转载)
C语言头文件的使用 ——by janders 转载请注名作者和出处,谢谢! C语言中的.h文件和我认识由来已久,其使用方法虽不十分复杂,但我却是经过了几个月的“不懂”时期,几年的“一知半解”时期才逐渐 ...
- 异常捕获 UncaughtExceptionHandler MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android -- DiskLruCache
DiskLruCache 创建一个磁盘缓存对象: public static DiskLruCache open(File directory, int appVersion, int valueCo ...
- 【收藏】介绍RCU的好文章
RCU原理: RCU(Read-Copy Update),顾名思义就是读-拷贝修改,它是基于其原理命名的.对于被RCU保护的共享数据结构,读者不需要获得任何锁就可以访问它,但写者在访问它时首先拷贝一个 ...
- awk的基本使用方法
awk是处理文本文件的一个应用程序,几乎所有 Linux 系统都自带这个程序. 它依次处理文件的每一行,并读取里面的每一个字段.对于日志.CSV 那样的每行格式相同的文本文件,awk可能是最方便的工具 ...
- 解析Linux操作系统文件目录
解析Linux操作系统文件目录 随着Linux的不断发展,越来越多的人开始使用Linux,对于那些刚刚接触的人来说,恐怕最先感到困惑的就是那些“不明不白”的目录了.如果想熟练使用Linux,让Linu ...