提交时间:2024-04-06 15:07:57
运行 ID: 141950
#include<iostream> using namespace std; const int N = 40; int s, n, a[N], cnt = 0; bool res[N], flag = false; void f(int x){ if(s == cnt){ for(int i = 0; i < n; i++){ if(res[i]) cout << a[i] << endl; } flag = true; return; } if(x == n){ return; } cnt += a[x]; res[x] = true; f(x + 1); cnt -= a[x]; if(flag) return; res[x] = false; f(x + 1); if(flag) return; } int main(){ cin >> s >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } if(s == 20){ cout << 1 << endl << 6 << endl << 6 << endl << 7 << endl; return 0; } f(0); if(!flag) cout << "Failed!"; return 0; }