/*
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 32766 //gobal variable====
int V;
int requirement[MAXV];
int G;
int feed[MAXG][MAXV];
int result;
int visited[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 t, int a[]){
if(t > V)
return;
if(t > result)
return;
if(check()){
if(t < result){
result = t;
for(int i = 0; i < t; i++){
res[i] = a[i];
}
}
return;
}
for(int i = 1; i <= G; i++){
if(visited[i] == 0){
visited[i] = 1;
for(int j = 1; j <= V; j++){
vit[j] += feed[i][j];
}
a[t] = i;
DFS(t + 1, a);
for(int j = 1; j <= V; j++){
vit[j] -= feed[i][j];
}
visited[i] = 0;
}
}
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];
}
}
result = 32766;
int ans[10000];
for(int i = 1; i <= G; i++){
memset(visited, 0, sizeof(visited));
memset(vit, 0, sizeof(vit));
visited[i] = 1;
for(int j = 1; j <= V; j++){
vit[j] += feed[i][j];
}
ans[0] = i;
DFS(1, ans);
}
cout<<result;
for(int i = 0; i < result; i++){
cout<<" "<<res[i];
}
cout<<endl;
return 0;
}

USACO holstein 超时代码的更多相关文章

  1. .NET, NETCORE 怎么写 "超时"代码,解析"超时"代码原理!

    干货:本人不会长篇大论.能贴上去的,就是干货,能用一两句话讲明白的,不会大讲概念,不会浪费大家宝贵的时间. 前言:我们发现,超时是个非常重要的概念,如果在通讯架构中,没有超时的设计,那么这个通讯架构就 ...

  2. linux 设置connect 超时代码[select/epoll]

    转载请注明来源:https://www.cnblogs.com/hookjc/ linux下socket编程有常见的几个系统调用: 对于服务器来说, 有socket(), bind(),listen( ...

  3. 已知一个日期和天数, 求多少天后的日期(是那个超时代码的AC版)

    #include <stdio.h> #include <string.h> ; int judge_year(int x) { == || x % == && ...

  4. USACO holstein AC code

    /* ID:kevin_s1 PROG:holstein LANG:C++ */ #include <iostream> #include <cstdio> #include ...

  5. asiHttpRequst 超时代码判断

    - (void)requestFailed:(ASIHTTPRequest *)request{ NSDictionary *userInfo = [request userInfo]; id del ...

  6. https://vjudge.net/contest/321565#problem/C 超时代码

    #include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...

  7. java-commons-HttpClient超时设置setConnectionTimeout和setSoTimeout

    问题 之前使用httpclient请求数据 源码方法: public static String doHttp(HttpMethod result, int timeout, String chars ...

  8. PHP超时处理全面总结

    [ 概述 ] 在PHP开发中工作里非常多使用到超时处理到超时的场合,我说几个场景: 1. 异步获取数据如果某个后端数据源获取不成功则跳过,不影响整个页面展现 2. 为了保证Web服务器不会因为当个页面 ...

  9. LeetCode()Substring with Concatenation of All Words 为什么我的超时呢?找不到原因了!!!

    超时代码 class Solution { public: vector<int> findSubstring(string s, vector<string>& wo ...

随机推荐

  1. 分析AWR报告

    1.AWR报告头信息 DB Name :数据库名字 DBid: 数据库id Elapsed:采样时间段 DB Time:用户操作花费的时间,不包括Oracle后台进程消耗的时间 DB Time远小于E ...

  2. nginx配置访问密码,让用户输入用户名密码才能访问

    如果我们在 nginx 下搭建了一些站点,但是由于站点内容或者流量的关系,我们并不想让所有人都能正常访问,那么我们可以设置访问认证.只有让用户输入正确的用户名和密码才能正常访问.效果如下: 在 ngi ...

  3. 洛谷P2391 白雪皑皑(并查集)

    题目背景 “柴门闻犬吠,风雪夜归人”,冬天,不期而至.千里冰封,万里雪飘.空中刮起了鸭毛大雪.雪花纷纷,降落人间. 美能量星球(pty 在 spore 上的一个殖民地)上的人们被这美景所震撼.但是 p ...

  4. how does Array.prototype.slice.call() work?

    763 down vote accepted +50 What happens under the hood is that when .slice() is called normally, thi ...

  5. 决策树构建算法之—C4.5

    这个网站值得收藏一下,原文链接:http://shiyanjun.cn/archives/428.html 决策树算法的优越性在于:离散学习算法进行组合总可以表达任意复杂的布尔函数,并不受数据集的限制 ...

  6. MFC多标签页对话框

    原文链接(有修改):http://blog.sina.com.cn/s/blog_6a1cdb3f0101llcw.html 1.新建一个MFC工程 取名PageSheet,选择Dialog base ...

  7. C++:数据流和缓冲区

    (1):C++之自定义的input缓冲区 原文链接:http://hi.baidu.com/nicker2010/item/d0c4cd2a7caf27c4ddf69aeb input stream用 ...

  8. java学习笔记3——异或

    异或原理: 转换两个字符或数为2进制的ASCII码,再按位异或,即 0001 0001 ---> 0000 0000 0000 ---> 0000 0001 0000 ---> 00 ...

  9. mvc cshtml 字符串操作

    @using System.Text; @{ ; string str=""; StringBuilder sb = new StringBuilder(); } @foreach ...

  10. Elasticsearch学习(一)————简单命令

    Elasticsearch一.简介**Elasticsearch 是一个分布式的搜索和分析引擎,可以用于全文检索.结构化检索和分析,并能将这三者结合起来.Elasticsearch 基于 Lucene ...