对于每一种饲料G(1<=G<=15),只有选和不选两种,所以直接枚举搜索即可
题目求问最少需多少种,所以dfs深度达到m时,就可以比较后return了
/*
ID:xsy97051
PROB:holstein
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,v[26],m,g[16][26],now[26],res[16],dat[16],minn=1000000000;
void dfs(int deep,int count)
{
if(deep==m+1)
{
for(int i=1;i<=n;i++)
if(now[i]<v[i]) return ;
if(count<minn)
{
minn=count;
for(int i=1;i<=minn;i++)
res[i]=dat[i];
}
return ;
}
for(int i=1;i<=n;i++)
now[i]+=g[deep][i];
dat[count+1]=deep;
dfs(deep+1,count+1);
for(int i=1;i<=n;i++)
now[i]-=g[deep][i];
dfs(deep+1,count);
return ;
}
int main()
{
freopen("holstein.in","r",stdin);
freopen("holstein.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
cin>>m;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
cin>>g[i][j];
memset(now,0,sizeof(now));
dfs(1,0);
cout<<minn;
for(int i=1;i<=minn;i++)
cout<<" "<<res[i];
cout<<endl;
return 0;
}