/*
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. PHP检测输入数据是否合法常用的类(转)

    <?php class Fun{ function isEmpty($val) { if (!is_string($val)) return false; //是否是字符串类型 if (empt ...

  2. UVA-1335(UVALive-3177) Beijing Guards 贪心 二分

    题面 题意:有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个相邻的人拥有同一种礼物,则双方都会很不高兴,问最少需要多少种不同的礼物才能满足所有人 ...

  3. python笔记:字符编码

    ASCII编码 知识点:计算机中最小的单位是bit,bit就咱们常说一位二进制,一位二进制要么是0 要么是 1.但是bit这个单位太小了,我们用字节(byte)来表示.换算的规则如下: 8b = 1B ...

  4. A - A Compatible Pair

    Problem description Nian is a monster which lives deep in the oceans. Once a year, it shows up on th ...

  5. 适配器模式(adapter)C++实现

    意图:将一个类的接口转换成客户希望的另一个接口. 适用性:1.你想使用一个已存在的类,而它的接口不符合你的需求. 2.你想创建一个可以复用的类,该类可以与其它不相关的类或不可预见的类协同工作. 类适配 ...

  6. 管窥python语法

    刚接触python,mark下所见所得: 1.Python调用底层API,可在任何platform上运行,包括Windows.Mac.Unix: 2.用#符号对代码或语句进行注释,#后的代码不被编译: ...

  7. date 格式化

    以这个为例:    yyyy-MM-dd HH:mm:ss 首先得写好你需要的模板 options.sign = options.sign || 'yyyy-MM-dd HH:mm:ss'; 其次就可 ...

  8. swift的属性与变量- Stored Properties and Instance Variables

    是一个概念 Stored Properties and Instance Variables If you have experience with Objective-C, you may know ...

  9. Postfix Self Expression

    Postfix Self Expression A postfix self expression consists of an expression or the name of a type, i ...

  10. Jquery插件:提示框

    在实际项目中,很容易有这种需求:当某个操作成功或失败,需要给用户一个提示.当然最简单的做法是调用alert()方法弹窗.但alert()属于JavaScript中BOM部分,每个浏览器的样式不太一样, ...