2,6,8,9,10WA了,求助(数据下下来太大了调不了),code:
#include <iostream>
#include <vector>
#include <cstring>
const int U = 30,G = 20;
int u,g,a[U],b[G][U];
std::vector<int> choose,ans;
void dfs(int x){
if (x > g){
int cnt[G];
memset(cnt,0,sizeof(cnt));
for (int i : choose)
for (int j = 1;j <= g;j++)
cnt[j] += b[i][j];
for (int i = 1;i <= g;i++)
if (cnt[i] < a[i])
return;
if (ans.empty() || choose.size() < ans.size()) ans = choose;
return;
}
choose.push_back(x);
dfs(x + 1);
choose.pop_back();
dfs(x + 1);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("P1460.in","r",stdin);
freopen("P1460.out","w",stdout);
struct NORE{~NORE(){exit(0);}}_;
#endif
std::cin.tie(0)->sync_with_stdio(0);
std::cin >> u;
for (int i = 1;i <= u;i++) std::cin >> a[i];
std::cin >> g;
for (int i = 1;i <= g;i++)
for (int j = 1;j <= u;j++)
std::cin >> b[i][j];
dfs(1);
std::cout << ans.size() << ' ';
for (int i : ans) std::cout << i << ' ';
return 0;
}