题目思路很简单,由于数据g<=15,所以很容易想到按位枚举,只是……在宿舍写的代码死也过不了,晚上到实验室重新写了一遍就过了……
/*
ID:Ryan
PROG:holstein
LANG:C++
*/
#include
< iostream >
#include
< fstream >
using   namespace  std;
int  a[ 16 ][ 26 ];
int  need[ 26 ],sum[ 26 ];
int  use[ 16 ],ans[ 16 ];
int  v,g,cnt,best = 16 ;
bool  can()
{   
int  i;
    
for (i = 1 ;i <= v;i ++ )
    {   
        
if (sum[i] < need[i])
            
return   0 ;
    }
    
return   1 ;
}
void  solve( int  k)
{
    
int  i,j;
    cnt
= 0 ;
    memset(sum,
0 , sizeof (sum));
    memset(use,
0 , sizeof (use));
    
for (i = 0 ;i < g;i ++ )
    {
        
if (k & ( 1 << i))
        {
            cnt
++ ;
            
if (cnt > best)
                
return  ;
            use[cnt]
= i + 1 ;
            
for (j = 1 ;j <= v;j ++ )
                sum[j]
+= a[i + 1 ][j];
        }
        
if (cnt < best && can())
        {
            best
= cnt;
            memcpy(ans,use,
sizeof (use));
        }
    }
}
int  main()
{   ifstream fin(
" holstein.in " );
    ofstream fout(
" holstein.out " );
    
int  i,j;
    fin
>> v;
    
for (i = 1 ;i <= v;i ++ )
        fin
>> need[i];
    fin
>> g;
    
for (i = 1 ;i <= g;i ++ )
        
for (j = 1 ;j <= v;j ++ )
            fin
>> a[i][j];
    
int  k;
    
for (k = 1 ;k < ( 1 << g);k ++ )
    {
        solve(k);
    }
    fout
<< best << "   " ;
    
for (i = 1 ;i < best;i ++ )
        fout
<< ans[i] << "   " ;
    fout
<< ans[i] << endl;
    
return   0
}