fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int ok,a[100], b[100],n,k;
  6.  
  7. bool check(){// cong cac thanh phan 1 1
  8. int sum=0;
  9. for(int i=1;i<=n;i++){
  10. sum += a[i]*b[i];
  11. }
  12. return sum==k;
  13. }
  14.  
  15. void sinh(vector<string>& ans){
  16. while(1){
  17. if(check()){// luu dap an
  18. string tmp = "";
  19. for(int i = 1; i <= n; i++) if(a[i]) tmp += to_string(b[i]) + " ";
  20. ans.push_back(tmp);
  21. }
  22. int i=n;
  23. while(i>0 && a[i]==1) a[i--]=0;
  24. if(i==0) return;
  25. a[i]=1;
  26. }
  27. }
  28.  
  29. int main(){
  30. cin >> n >> k;
  31. for(int i=1;i<=n;i++){
  32. cin >> b[i];
  33. a[i]=0;
  34. }
  35. vector<string> ans;
  36. sinh(ans);
  37. for(auto x : ans) cout<<x<<"\n";
  38. cout<<ans.size()<<"\n";
  39. }
Success #stdin #stdout 0.01s 5284KB
stdin
5 50
5 10 15 20 25
stdout
10 15 25 
5 20 25 
5 10 15 20 
3