USACO holstein 超时代码
/*
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 超时代码的更多相关文章
- .NET, NETCORE 怎么写 "超时"代码,解析"超时"代码原理!
干货:本人不会长篇大论.能贴上去的,就是干货,能用一两句话讲明白的,不会大讲概念,不会浪费大家宝贵的时间. 前言:我们发现,超时是个非常重要的概念,如果在通讯架构中,没有超时的设计,那么这个通讯架构就 ...
- linux 设置connect 超时代码[select/epoll]
转载请注明来源:https://www.cnblogs.com/hookjc/ linux下socket编程有常见的几个系统调用: 对于服务器来说, 有socket(), bind(),listen( ...
- 已知一个日期和天数, 求多少天后的日期(是那个超时代码的AC版)
#include <stdio.h> #include <string.h> ; int judge_year(int x) { == || x % == && ...
- USACO holstein AC code
/* ID:kevin_s1 PROG:holstein LANG:C++ */ #include <iostream> #include <cstdio> #include ...
- asiHttpRequst 超时代码判断
- (void)requestFailed:(ASIHTTPRequest *)request{ NSDictionary *userInfo = [request userInfo]; id del ...
- https://vjudge.net/contest/321565#problem/C 超时代码
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- java-commons-HttpClient超时设置setConnectionTimeout和setSoTimeout
问题 之前使用httpclient请求数据 源码方法: public static String doHttp(HttpMethod result, int timeout, String chars ...
- PHP超时处理全面总结
[ 概述 ] 在PHP开发中工作里非常多使用到超时处理到超时的场合,我说几个场景: 1. 异步获取数据如果某个后端数据源获取不成功则跳过,不影响整个页面展现 2. 为了保证Web服务器不会因为当个页面 ...
- LeetCode()Substring with Concatenation of All Words 为什么我的超时呢?找不到原因了!!!
超时代码 class Solution { public: vector<int> findSubstring(string s, vector<string>& wo ...
随机推荐
- jQuery不熟点总结
jQuery 事件 1 .trigger() 方法触发被选元素的指定事件类型. 2 .delegate() 事件委派 1.不占内存2.可以给未来元素(后期动态添加的元素)添加事件. 2. 添加元 ...
- 树莓派-基于aria2实现离线下载
安装aria2 aria2是linux下的一个下载工具,它支持http.bt种子.磁力链接三种方式下载 sudo apt-get install aria2 配置aria2 aria2支持命令参数,也 ...
- window 10 多版本激活工具
window 10 通用版激活工具 云盘地址:https://pan.baidu.com/s/1bo3L4Kn 激活工具网站:http://www.tudoupe.com/win10/win10jih ...
- jumpserver install
本文来源jumpserver官网 一步一步安装 环境 系统: CentOS 7 IP: 192.168.244.144 关闭 selinux 和防火墙 # CentOS 7 $ setenforce ...
- 《剑指offer 第二版》题解
剑指Offer 按题号排序 面试题 3:数组中重复的数字 面试题 4:二维数组中的查找 面试题 5:替换空格 面试题 6:从头到尾打印链表 面试题 7:重建二叉树 面试题 8:二叉树的下一个节点 面试 ...
- css简单介绍
css层叠样式表,主要作用就是解决内容与表现分离的问题.html标签有自己的意义当然也是有自己的默认样式的,但有时候我们想修改他的样式,这时候就需要了css. 例:给字体加上颜色,我们有如下几种方法: ...
- 2018最新WordPress缩略图设置方法
缩略图设置的方法很多,但都不全面,且很多教程已经失效了,其中使用插件来实现,可是那些插件都使用过都不能实现效果,所以我整理了一份使用代码实现缩略图的方法. 1.找到网站根目录/wp-content/t ...
- hdu2853 Assignment 完美匹配 多校联赛的好题
PS:好题.不看题解绝对AC不了. 题解来源: http://blog.csdn.net/niushuai666/article/details/7176290 http://www.cnblogs. ...
- hdu2819 Swap 最大匹配(难题)
题目大意: 给定一个元素的值只有1或者0的矩阵,每次可以交换两行(列),问有没有方案使得对角线上的值都是1.题目没有限制需要交换多少次,也没限制行交换或者列交换,也没限制是主对角线还是副对角线.虽然没 ...
- class A<T> where T:new()相关知识点
来源:http://www.cnblogs.com/FredWang/p/4284251.html class A<T> where T:new() ===>>> ...