Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
125648 | 陈未一 | 健康的奶牛 | C++ | 通过 | 100 | 1 MS | 260 KB | 850 | 2024-01-23 20:00:06 |
#include <bits/stdc++.h> using namespace std; int V,G,need[30],feed[20][30],ansN=1e9,tmp[20],sum[30],ans[30]; bool OK(){ for(int i=1; i<=V; i++) if(sum[i]<need[i]) return false; return true; } void DFS(int cur){ for(int i=tmp[cur-1]+1; i<=G; i++) { tmp[cur]=i; for(int j=1; j<=V; j++) sum[j]+=feed[i][j]; if(OK() && cur<ansN) { ansN=cur; for(int j=1; j<=ansN; j++) ans[j]=tmp[j]; } else if(cur+1<ansN) DFS(cur+1); for(int j=1; j<=V; j++) sum[j]-=feed[i][j]; } } int main(){ cin>>V; for(int i=1; i<=V; i++) cin>>need[i]; cin>>G; for(int i=1; i<=G; i++) for(int j=1; j<=V; j++) cin>>feed[i][j]; DFS(1); cout<<ansN<<' '; for(int i=1; i<=ansN; i++) cout<<ans[i]<<(i==ansN?'\n':' '); return 0; }