Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
142715 | C班詹皓杰 | 简单背包问题 | C++ | 解答错误 | 80 | 0 MS | 248 KB | 560 | 2024-04-08 22:27:24 |
#include<iostream> #include<vector> using namespace std; int a[50]; int ans[50]; bool suc = false; int size; void serach(int step,int ls,int n){ if(ls == 0){ for(int i = 0; i < n; i++){ cout<<ans[i]<<'\n'; } exit(0); return; } else if(ls<0 || step==size-1){ return; }else{ serach(step+1,ls,n); ans[n] = a[step]; serach(step+1,ls-a[step],n+1); ans[n] = a[step]; } } int main(){ int s; cin>>s>>size; for(int i = 0; i < size; i++){ cin>>a[i]; } serach(0,s,0); cout<<"Failed!"; return 0; }