记录编号 111681 评测结果 AAAAAAAAAA
题目名称 [USACO 2.1] 荷斯坦奶牛 最终得分 100
用户昵称 Gravatarwolf 是否通过 通过
代码语言 C++ 运行时间 0.009 s
提交时间 2014-07-13 19:30:54 内存使用 0.31 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
class Vt{
public:
	int num;
	vector<int> V;
	Vt(int a){
		num=a;
	}
};
FILE *in,*out;
int N,every,G;
vector<Vt> all;
vector<int> need;
vector<int> way;
vector<int> end;
void pri(vector<int> &a){
	for(int i=0;i!=a.size();++i){
		fprintf(out,"%d  ",a[i]);
		//cout<<a[i]<<"  ";
	}
	//cout<<endl;
}
void work(int n,bool a){
	if(a){
		for(int i=0;i!=N;++i){
			need[i]=need[i]-all[n].V[i];
		}
	}else{
		for(int i=0;i!=N;++i){
			need[i]=need[i]+all[n].V[i];
		}
	}
}
/////////////////////
bool ch(){
	for(int i=0;i!=need.size();++i){
		if(need[i]>0)
			return 0;
	}
	return 1;
}
void core(int t){
	//cout<<t<<endl;
	if(ch()&&way.size()<end.size()){
		end=way;
	}
	for(int i=t+1;i!=G;++i){
		work(i,1);
		way.push_back(i+1);
		core(i);
		work(i,0);
		way.pop_back();
	}
}
int main(){
	in=fopen("holstein.in","r");
	out=fopen("holstein.out","w");
	fscanf(in," %d",&N);
	for(int i=0;i!=N;++i){
		int e;
		fscanf(in," %d",&e);
		need.push_back(e);
	}
	fscanf(in," %d",&G);
	for(int i=1;i!=G+1;++i){
		Vt e(i);
		for(int i=0;i!=N;++i){
			int c;
			fscanf(in," %d",&c);
			e.V.push_back(c);
		}
		all.push_back(e);
	}
	end.resize(20);
	core(-1);
	fprintf(out,"%d  ",end.size());
	pri(end);
	return 0;
}
//designed by wolf