提交时间:2024-01-23 09:41:44

运行 ID: 123762

#include<bits/stdc++.h> using namespace std; int v,wtm[26],g,sl[16][26],ans=0x7fffffff; bool used[16],ansuse[16]; void dfs(int depth){ if(depth>g){ int cnt=0,sum[26]; memset(sum,0,sizeof(sum)); for(int i=1;i<=g;i++){ if(used[i]){ cnt++; for(int j=1;j<=v;j++){ sum[j]+=sl[i][j]; } } } for(int i=1;i<=v;i++){ if(sum[i]<wtm[i])return; } if(cnt<ans){ ans=cnt; for(int i=1;i<=g;i++){ ansuse[i]=used[i]; } } return; } used[depth]=1; dfs(depth+1); used[depth]=0; dfs(depth+1); } int main(){ cin>>v; for(int i=1;i<=v;i++){ cin>>wtm[i]; } cin>>g; for(int i=1;i<=g;i++){ for(int j=1;j<=v;j++){ cin>>sl[i][j]; } } dfs(1); cout<<ans<<" "; for(int i=1;i<=v;i++){ if(ansuse[i])cout<<i<<" "; } return 0; }